• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need Help Please

 
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic