This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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. Thankyou
I don't have a KeyboardReader so I used an old fashoned reader that should work in most versions of java
Joined: Aug 24, 2005
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)
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).
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Joined: Aug 24, 2005
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.