File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes problem writing program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "problem writing program" Watch "problem writing program" New topic

problem writing program

Christie Apps

Joined: Aug 24, 2005
Posts: 5
I am fairly new to Java, and am in the process of writing a program that will engage a user in conversation and i seem to keep getting stuck and find myself looking at it too much which makes me even more confused. My issues at the moment are :
1. It tells me the variable name might not have been initialized
I am sure I had this working ok before so am not sure what I've done.

and 2. Once it reads the first question and the user types in the letter A, B or C and it gives the response I can't get it to then ask the next question!

If anyone understands what I'm trying to do and can help give me a big push in the right direction please do, I would really appreciate any input.
Thomas Paul Bigbee
Ranch Hand

Joined: Jun 28, 2005
Posts: 71
Name isn't initialized, its local to the methods, method variables need to be initialized before they can be used, where as instance (class) variables are initialized to their default values

Furthermore, the case statements are taking literals so 'A' does note equal 'a'

I don't really know what KeyboardReader is doing (Its probably some sort of however it's not listed in my version of 1.5, so I can't help you there.

Hope this helps
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
I don't have a KeyboardReader so I used an old fashoned reader that should work
in most versions of java
Christie Apps

Joined: Aug 24, 2005
Posts: 5
Thankyou both so much, I think I am now getting somewhere!
I took out the try catch throw bit as I have not learnt that yet, and was a little confused by it
Only problem now is that when i execute it i get the following error
Exception in thread "main" java.lang.NoClassDefFoundError: Assignment1

I have added text (another 3 sets of questions and answers) and changed back to keyboardreader (as that is what we are to use)

Here is my KeyboardReader Code

And here is my program code (I hope it is not too long to put in a post, if it is I will edit it immediately)
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
Hi, Christie,

Welcome to JavaRanch.

First a bit of business. Please adjust your display name to meet the JavaRanch Naming Policy.
You can change it here. Thanks.

Now for your question. When I run your program, it seems to work just fine. Therefore, I think the problem is not with your code. Additionally, the error that you mention "Exception in thread "main" java.lang.NoClassDefFoundError: Assignment1" is pretty specific to CLASSPATH issues.

There are a couple of ways to handle classpath. One is to set it globally in your environment. The other is to use the -cp switch on the java command.

If you go into the Java in General (beginner) forum, you will probably see several threads on how to set the classpath (without even doing a search).

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Christie Apps

Joined: Aug 24, 2005
Posts: 5
Thankyou very much
Yes I think the software that has been supplied may have a few glitches, might have to have a look around for something different!
About my name Christie is my first name and I thought that was what I was supposed to use I didn't realise I had to use my first AND last name, sorry, I have now changed it.
I agree. Here's the link:
subject: problem writing program
It's not a secret anymore!