File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Need Help Please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Need Help Please" Watch "Need Help Please" New topic
Author

Need Help Please

Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
Hello Everybody:
I downloaded FBN assignment. Read few times instruction and went through all source code. They supplied four classes and one Binary db.db. I have two problems. Anybody please help me. I appreciate any response.
1.I wanted to view content of db.db. I opened it using notepad. I see some black squares. I opened type db.db on DOS PROMPT. I see heart, spade, diamond, and some other symbols. I want to see programmatically how db.db is oraganized? I added main method in Data.java file for my testing purpose.
public static void main(String[] args) throws IOException {
new Data("db.db");
}
Added few System.out.println in its first constructor to view at data.
.....
headerLen = db.readInt();
System.out.println(headerLen);
int nFields= db.readInt();
System.out.println(nFields);
recordCount = db.readInt();
System.out.println(recordCount);
description = new FieldInfo[nFields];
for (int i=0; i<nFields; i++) {<br /> description[i] = new FieldInfo(db.readUTF(), db.readInt());<br /> recordLen += description[i].getLength();<br /> System.out.println(description[i].getName());<br /> System.out.println(description[i].getLength());<br /> }.....<br /> I complied as below:<br /> A:\scjd\starting>javac suncertify\db\Data.java
Note: suncertify\db\Data.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
Got message for -deprecation for details and compiled fine. At the run time I am getting following errors.
A:\scjd\starting>java suncertify\db\Data
Exception in thread "main" java.lang.NoClassDefFoundError: suncertify\db\Data
wrong name: suncertify/db/Data)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
How to handle this? First I want to understand their db.db setting. How to dump out contents of db.db so I can think simple GUI?
2.Instruction says we have to enhance Data class. It requires to implement criteriaFind(), lock(), and unlock() methods. I see lock and unlock methods. But I do not see criteriaFind. Is it we have to add new method in Data class?
Bear with me guys I will keep asking lot of questions. Thanks in advance for your time and response. BK
Ian B Anderson
Ranch Hand

Joined: Jun 26, 2001
Posts: 275
Hello,
1) The data file is a serialized file. You can't open it in Notepad etc. Look at the methods to access the data in the Data class. Use these to display the entire file etc. (You are going about this in the right way judging by your code).
2) You don't appear to have the current directory included in your classpath try:
A:\scjd\starting>javac -classpath . suncertify\db\Data.java
or instead of the . put a:\scjd\starting\
And lastly yes you would need to add the criteraFind() method yourself.
Good luck
Ian
[This message has been edited by Ian B Anderson (edited November 06, 2001).]
Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
Thanks Ian for your prompt response. I complied as
A:\scjd\starting>javac -classpath .suncertify\db\Data.java
I am surprised it did not even complain about deprecated methods.
I have just mend my main method as below other parts are sun provided.
public static void main(String[] args) throws IOException {
Data d = new Data("db.db");
System.out.println("Record count is: " + d.getRecordCount());
}
When I ran I got following errors.
A:\scjd\starting>java suncertify\db\Data
Exception in thread "main" java.lang.NoClassDefFoundError: suncertify\db\Data (wrong name: suncertify/db/Data)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
A:\scjd\starting>
Your input in this regard highly appreciated. Once I get started I will get rolling. Thanks

A:\scjd\starting>javac -classpath . suncertify\db\Data.java

Ian B Anderson
Ranch Hand

Joined: Jun 26, 2001
Posts: 275
Hello,
Instead of this:
A:\scjd\starting>java suncertify\db\Data
try this:
A:\scjd\starting>java -cp . suncertify.db.Data
Also if you want to see the deprecated methods when you compile you would need to do this:
A:\scjd\starting>javac -classpath . -deprecation suncertify\db\Data.java
Ian
Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
Thanks Ian. Light is coming on. It compiles and runs. It is my great surprise that it is not recognizing db.db file. I am getting result from 1stconstructor ELSE section Data: request to open non-existant file. What is going on? I see in code RandomAccessFile is marked as �rw�. It should not be a problem to read and write. There is file in directory. Why first condition is being false?
You know what! I had opened db.db file using notepad. Since then I see notepad icon for db.db. It is not a problem. Is it?
The following is ouput:
A:\scjd\starting>java -cp . suncertify.db.Data
Exception in thread "main" java.io.IOException: Data: request to open non-existant or inaccessible file db.db
at suncertify.db.Data.<init>(Data.java:60)
at suncertify.db.Data.main(Data.java:376)
A:\scjd\starting>
Hope I am not being pain for you. Thank you.

try this:
A:\scjd\starting>java -cp . suncertify.db.Data

Ian B Anderson
Ranch Hand

Joined: Jun 26, 2001
Posts: 275
Hello,
For now put the full path to the data file in the constructor. E.g.
Data d = new Data("db.db");
would become
Data d = new Data("A:\scjd\starting\suncertify\db\db.db");
Also it doesn't matter about the Notepad icon.
Ian

[This message has been edited by Ian B Anderson (edited November 06, 2001).]
Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
It did not like back slash, gave me seven errors. I changed it to forward slash, no problem complied. I cann't believe, it is working now. Thank you sir for your help. I have to do more home work now. Thank you again. BK
 
 
subject: Need Help Please