Good Evening. I am hoping you all can assist me with an issue I am having. I will preface this question wtih the fact that I am very new to Java and this is my first class so please forgive me if this is a "stupid" question. I have the infamous Inventory Program with GUI interface written and running (functioning without error) in NetBeans. When, however, I attempt to run the same code within TextPad, from a command prompt, it compiles without error but when running I receive the following:
Exception in thread "main" java.lang.NoClassDefFoundError: Inventory5 (wrong name: inventory5/Inventory5)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(unknown Source)
And 11 other "at java." errors.
If you require the code in order to assist, I am happy to post that, just let me know. Any assistance you can offer would be greatly appreciated.
Thank you!
James
7 Replies - 808 Views - Last Post: 23 September 2011 - 11:04 PM
#1
Receiving error when running from cmd prompt but not NetBeans?
Posted 23 September 2011 - 10:21 PM
Replies To: Receiving error when running from cmd prompt but not NetBeans?
#2
Re: Receiving error when running from cmd prompt but not NetBeans?
Posted 23 September 2011 - 10:30 PM
Let me guess: you're typing
>> java inventory5/Inventory5
is that right?
Change down into the inventory5 directory and try running it as
>> java Inventory5
What I think is happening is that you're telling it to look in a directory, which java interprets as looking into a package... but if you don't have a package declaration, it gets confused.
>> java inventory5/Inventory5
is that right?
Change down into the inventory5 directory and try running it as
>> java Inventory5
What I think is happening is that you're telling it to look in a directory, which java interprets as looking into a package... but if you don't have a package declaration, it gets confused.
#3
Re: Receiving error when running from cmd prompt but not NetBeans?
Posted 23 September 2011 - 10:38 PM
I wish it were that easy!
I am actually in the directory in which I have stored the files and typing: java Inventory5 in order to execute the program. I am hoping it is something simple that I am overlooking but have been racking my brain trying to understand why the program will function properly in NetBeans but not from TextPad/command prompt...
Thanks for any additional suggestions.
-James
Thanks for any additional suggestions.
-James
#4
Re: Receiving error when running from cmd prompt but not NetBeans?
Posted 23 September 2011 - 10:41 PM
Does your class has a package statement ?
F*** good guess +1.... I am still guess you are right
jon.kiparsky, on 24 September 2011 - 01:30 AM, said:
Let me guess: you're typing
>> java inventory5/Inventory5
is that right?
Change down into the inventory5 directory and try running it as
>> java Inventory5
What I think is happening is that you're telling it to look in a directory, which java interprets as looking into a package... but if you don't have a package declaration, it gets confused.
>> java inventory5/Inventory5
is that right?
Change down into the inventory5 directory and try running it as
>> java Inventory5
What I think is happening is that you're telling it to look in a directory, which java interprets as looking into a package... but if you don't have a package declaration, it gets confused.
F*** good guess +1.... I am still guess you are right
#5
Re: Receiving error when running from cmd prompt but not NetBeans?
Posted 23 September 2011 - 10:53 PM
YES!!! Thank you for the point in the right direction!! My first line stated:
package inventory5;
I needed // in front and I am good to go.
Thanks again!!
-James
package inventory5;
I needed // in front and I am good to go.
Thanks again!!
-James
#6
Re: Receiving error when running from cmd prompt but not NetBeans?
Posted 23 September 2011 - 10:55 PM
Then I had it the wrong way around. (I knew it was one or the other.) Try running it from one directory up:
>>java inventory5/Inventory5
If the first line of your source files reads "package inventory5;" then I've probably got it right this time.
EDIT: Mr. Slow Typist loses again...
>>java inventory5/Inventory5
If the first line of your source files reads "package inventory5;" then I've probably got it right this time.
EDIT: Mr. Slow Typist loses again...
This post has been edited by jon.kiparsky: 23 September 2011 - 10:56 PM
#7
Re: Receiving error when running from cmd prompt but not NetBeans?
Posted 23 September 2011 - 10:59 PM
If you are a newbie in Java, forget about Java package statement for now...
You will have plenty of time to learn about them
Just delete them from all your source code
Happy coding
You will have plenty of time to learn about them
Just delete them from all your source code
Happy coding
#8
Re: Receiving error when running from cmd prompt but not NetBeans?
Posted 23 September 2011 - 11:04 PM
jbfode, on 24 September 2011 - 12:53 AM, said:
I needed // in front and I am good to go.
Trouble with this solution is it's likely to bite you on the hinder parts when you go to run it in NetBeans again, since NetBeans will be expecting a package declaration. This is an awkward part of running programs in different environment - java just doesn't make it easy all the time. You have a few options, if you want to make it easy (I don't count "adding and commenting out package declarations for different environments as easy!)
Probably the best all around would be to deploy ant and set up a task to compile to an executable jar. Then you can just run the jar (or an ant task to run the jar, if you're lazy, or an autogenerated shell script to fire the jar if you're lazy like me)
This post has been edited by jon.kiparsky: 23 September 2011 - 11:09 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|