7 Replies - 1091 Views - Last Post: 23 September 2011 - 11:04 PM Rate Topic: -----

#1 jbfode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-September 11

Receiving error when running from cmd prompt but not NetBeans?

Posted 23 September 2011 - 10:21 PM

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

Is This A Good Question/Topic? 0
  • +

Replies To: Receiving error when running from cmd prompt but not NetBeans?

#2 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7629
  • View blog
  • Posts: 12,858
  • Joined: 19-March 11

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.
Was This Post Helpful? 1
  • +
  • -

#3 jbfode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-September 11

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
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

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 ?

View Postjon.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.

F*** good guess +1.... I am still guess you are right :)
Was This Post Helpful? 0
  • +
  • -

#5 jbfode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-September 11

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
Was This Post Helpful? 0
  • +
  • -

#6 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7629
  • View blog
  • Posts: 12,858
  • Joined: 19-March 11

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... :)

This post has been edited by jon.kiparsky: 23 September 2011 - 10:56 PM

Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

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
Was This Post Helpful? 0
  • +
  • -

#8 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7629
  • View blog
  • Posts: 12,858
  • Joined: 19-March 11

Re: Receiving error when running from cmd prompt but not NetBeans?

Posted 23 September 2011 - 11:04 PM

View Postjbfode, 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1