Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Runtime Error in Eclipse

2 views
Skip to first unread message

Uncle Scotty

unread,
Oct 4, 2005, 10:39:38 PM10/4/05
to
I am running Eclipse 3.1.1. I created a project, called PizzaShop.
Inside pizza shop, I have src\ lib\ and build\classes\ folders. Inside
src\, I have a pizza folder for the pizza package. That too is mirrored
in build\classes\pizza.

When I go to debug as ->debug, Eclipse tells me:

java.lang.NoClassDefFoundError: pizza/SystemTest
Exception in thread "main"

What does that mean and how do you tell Eclipse which main to run? I
think I tell it that when it pops open the configuration menu, and I
tell it "pizza.TakeOrder" for the main class to run. But, obviously, it
cannot find the main, and there is a public main() in the TakeOrder
file.

So confused, Scott

Andrew Thompson

unread,
Oct 4, 2005, 10:57:15 PM10/4/05
to
Uncle Scotty wrote:

> ..But, obviously, it


> cannot find the main, and there is a public main() in the TakeOrder
> file.

Is that a
public static void main(String[] args)
?

Accept no substitutes. Java doesn't.

> So confused, Scott

A better groups for Java beginners is..
<http://www.physci.org/codes/javafaq.jsp#cljh>.

Uncle Scotty

unread,
Oct 4, 2005, 11:12:11 PM10/4/05
to
Yes, it is public static void main(String[] args). So, why can't
Eclipse find that method?

Andrew Thompson

unread,
Oct 5, 2005, 2:22:59 AM10/5/05
to
Uncle Scotty wrote:

> Yes, it is public static void main(String[] args). So, why can't
> Eclipse find that method?

(shrugs) I don't provide support for Eclipse.

OTOH, If you figure how to do it from the command line,
you'll probably realise what is misconfigured in Eclipse
(or quite possibly, solve the underlying Java problem).

Uncle Scotty

unread,
Oct 5, 2005, 9:01:20 AM10/5/05
to
I am not sure if I did what you suggested correctly, but I tried
running from the command line like below and am still getting the same
error message! Does that tell me something useful? When I try to get
Eclipse (I know you don't support this tool, I was just hoping that it
would tell you something generically useful) to show me that classfile,
I do get the error message that Eclipse gives me when I try to run
it...

"Class File Editor
Source Not Found
There is no source file attached to this class file SystemTest.class"

When I look in C:\Documents and Settings\Scott
Spiegler\workspace\PizzaShop\src\pizza, I definitely see
SystemTest.java, so I don't understand what it is telling me.

Anyway, here is the error message when I try to run via the command
line...

C:\Documents and Settings\Scott
Spiegler\workspace\PizzaShop\build\classes\pizza
>java SystemTest
Exception in thread "main" java.lang.NoClassDefFoundError: SystemTest
(wrong nam
e: pizza/SystemTest)
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)

Andrew Thompson

unread,
Oct 5, 2005, 9:46:35 AM10/5/05
to
Uncle Scotty wrote:

> I am not sure if I did what you suggested correctly, but I tried
> running from the command line like below and am still getting the same
> error message! Does that tell me something useful?

Your messages tell us a number of things..

> Anyway, here is the error message when I try to run via the command
> line...
>
> C:\Documents and Settings\Scott
> Spiegler\workspace\PizzaShop\build\classes\pizza
>
>>java SystemTest
>
> Exception in thread "main" java.lang.NoClassDefFoundError: SystemTest
> (wrong nam
> e: pizza/SystemTest)

This line suggests to me that your class is in the 'pizza'
package. Do you understand packages? They are the key
to fixing (the command line aspect of) this problem.

Uncle Scotty

unread,
Oct 5, 2005, 10:46:42 AM10/5/05
to
Yes, it is in the pizza package. When I run it from the command line
from the classes folder, I get this:

C:\Documents and Settings\Scott

Spiegler\workspace\PizzaShop\build\classes>java
pizza.SystemTest
FILE: c:\Documents and Settings\Scott
Spiegler\workspace\PizzaShop\business layer test.txt
admin initializes system
java.lang.ClassNotFoundException:
oracle.jdbc.OracleDriver
using connection string:
jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2
Connecting to the database...java.sql.SQLException: No
suitable driver
at
java.sql.DriverManager.getConnection(Unknown Source)
at
java.sql.DriverManager.getConnection(Unknown Source)
at pizza.DAO.getDBConnection(DAO.java:81)
at pizza.DAO.<init>(DAO.java:14)
at pizza.DAOAdmin.<init>(DAOAdmin.java:13)
at
pizza.SystemTest.readFile(SystemTest.java:28)
at pizza.SystemTest.main(SystemTest.java:130)
setupShop() starts here
Creating statement object
Exception in thread "main"
java.lang.NullPointerException
at pizza.DAOAdmin.setupShop(DAOAdmin.java:28)
at
pizza.SystemTest.readFile(SystemTest.java:29)
at pizza.SystemTest.main(SystemTest.java:130)

So, then I tell it about the ojdbc14.jar file, and it gives me the
original error message. I am really confused:

C:\Documents and Settings\Scott

Spiegler\workspace\PizzaShop\build\classes>java
-classpath ../../lib/ojdbc14.jar pizza.SystemTest
Exception in thread "main"
java.lang.NoClassDefFoundError: pizza/SystemTest

Uncle Scotty

unread,
Oct 5, 2005, 10:49:42 AM10/5/05
to
Actually, I didn't really answer your question, sorry. I only know that
it is about organization of useful chunks of functionality. So, I put
all my src and hence build\classes files in a subfolder called pizza
And, at the top of each source page, I put "package pizza;".

That is what I know about packages in Java...

Andrea Desole

unread,
Oct 5, 2005, 11:15:31 AM10/5/05
to

Uncle Scotty wrote:
>
> So, then I tell it about the ojdbc14.jar file, and it gives me the
> original error message. I am really confused:
>
> C:\Documents and Settings\Scott
> Spiegler\workspace\PizzaShop\build\classes>java
> -classpath ../../lib/ojdbc14.jar pizza.SystemTest
> Exception in thread "main"
> java.lang.NoClassDefFoundError: pizza/SystemTest

what is SystemTest? Is it by chance a JUnit test? Does it extend or
implement anything? Can you post the code?

Uncle Scotty

unread,
Oct 5, 2005, 11:29:21 AM10/5/05
to
I discovered one error. I was using the unix ':' from the command line
rather than the Windows ';', when I told java about the classpath for
the jar. Now, it runs as expected. The only question is how do I
straighten out Eclipse so that it does what I want it to?

C:\Documents and Settings\Scott

Spiegler\workspace\PizzaShop\build\classes>java
-classpath ../../lib/ojdbc14.jar;. pizza.SystemTest
FILE: c:\Documents and Settings\Scott
Spiegler\workspace\PizzaShop\business lay
r test.txt
admin initializes system


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.


setupShop() starts here
Creating statement object

Dropping contains_a table...
Dropping has_a table...
Dropping orders table...
Dropping toppings table...
Dropping sizes table...
Dropping nextorder table...
Dropping day table...
orders table created...
toppings table created...
contains_a table created...
sizes table created...
has_a table created...
nextorder table created...
day table created...
Initializing next order table
Initializing day table


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.
addToppings() starts here
Inserting into tables: insert into toppings (toppingid,topping) values
(1,'pepp
roni')
pepperoni topping was inserted.


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.
addToppings() starts here
Inserting into tables: insert into toppings (toppingid,topping) values
(2,'onio
s')
onions topping was inserted.


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.
addToppings() starts here
Inserting into tables: insert into toppings (toppingid,topping) values
(3,'mush
oom')
mushroom topping was inserted.


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.
addToppings() starts here
Inserting into tables: insert into toppings (toppingid,topping) values
(4,'hot
eppers')
hot peppers topping was inserted.


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.
addToppings() starts here
Inserting into tables: insert into toppings (toppingid,topping) values
(5,'extr
cheese')
extra cheese topping was inserted.


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.
addSizes() starts here
Inserting into sizes tables: insert into sizes (sizeid,piesize) values
(1,'smal
')
small size was inserted.


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.
addSizes() starts here
Inserting into sizes tables: insert into sizes (sizeid,piesize) values
(2,'medi
m')
medium size was inserted.


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.
addSizes() starts here
Inserting into sizes tables: insert into sizes (sizeid,piesize) values
(3,'larg
')
large size was inserted.
student order from room 5


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.
Execution Completed: select orderid from nextorder
Order #100 inserted...
Query string: insert into contains_a (orderid,toppingid) values (100,1)
Query string: insert into contains_a (orderid,toppingid) values (100,3)
Your insert into contains_a worked.
Query string: insert into has_a (orderid,sizeid) values (100,3)
Your insert into has_a worked.
Orders submitted:
Order ID Day Room Number Cooked Closed
100 1 5 0 0
student order from room 1


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.
Execution Completed: select orderid from nextorder
Order #101 inserted...
Query string: insert into contains_a (orderid,toppingid) values (101,1)
Query string: insert into contains_a (orderid,toppingid) values (101,3)
Your insert into contains_a worked.
Query string: insert into has_a (orderid,sizeid) values (101,3)
Your insert into has_a worked.
Orders submitted:
Order ID Day Room Number Cooked Closed
100 1 5 0 0
101 1 1 0 0
status of orders from room n


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.
Your order is not completed
baker reports pizza done


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.
Cooking pizzas:
Order # 1for day 100 is cooked
status of orders from room n


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.
Your order is not completed
admin status report for today
baker reports day is done


using connection string: jdbc:oracle:thin:@dbs2.cs.umb.edu:1521:dbs2

Connecting to the database...connected.
Ending day:
Executing: select MAX(today) from day
generate admin college report on completed days since last such report

Uncle Scotty

unread,
Oct 5, 2005, 11:31:17 AM10/5/05
to
SystemTest is not a JUnit test. It is something I rolled myself. It is
a business layer test that just parses this file that gives terse
commands to the system and then calls the appropriate API to drive the
basic functionality of the system. Here is the source below:

package pizza;
import java.io.FileReader;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;

public class SystemTest
{

public static void readFile(String fileName)
{
FileReader theFile;
BufferedReader fileIn = null;
String oneLine;
String whichDatabase="oracle";
System.out.println( "FILE: " + fileName );
try
{
theFile = new FileReader( fileName );
fileIn = new BufferedReader( theFile );
while( ( oneLine = fileIn.readLine( ) ) != null )
{
//admin initializes system

if(oneLine.substring(0,1).equals("a")&&oneLine.substring(1,2).equals("i"))
{
System.out.println("admin initializes system");
DAOAdmin daoAdmin = new DAOAdmin("1",whichDatabase);
daoAdmin.setupShop();
//Initialize toppings table
daoAdmin = new DAOAdmin("2",whichDatabase);
daoAdmin.addTopping("pepperoni");
daoAdmin = new DAOAdmin("2",whichDatabase);
daoAdmin.addTopping("onions");
daoAdmin = new DAOAdmin("2",whichDatabase);
daoAdmin.addTopping("mushroom");
daoAdmin = new DAOAdmin("2",whichDatabase);
daoAdmin.addTopping("hot peppers");
daoAdmin = new DAOAdmin("2",whichDatabase);
daoAdmin.addTopping("extra cheese");
//Initialize sizes table
daoAdmin = new DAOAdmin("4",whichDatabase);
daoAdmin.addSize("small");
daoAdmin = new DAOAdmin("4",whichDatabase);
daoAdmin.addSize("medium");
daoAdmin = new DAOAdmin("4",whichDatabase);
daoAdmin.addSize("large");
}
//student order from room n
else
if(oneLine.substring(0,1).equals("s")&&oneLine.substring(1,2).equals("o"))
{
int roomno=Integer.parseInt(oneLine.substring(2,3));
System.out.println("student order from room "+roomno);
ArrayList toppings = new ArrayList();
//Pepperoni
toppings.add("1");
//Mushrooms
toppings.add("3");
//Order large pizza
String size = "3";
OrderTO orderTO=new OrderTO(100,1,roomno,new
Pizza(size,toppings),false);
DAOOrder daoOrder = new DAOOrder(orderTO,whichDatabase);
daoOrder.sendOrder(whichDatabase);
}
//status of orders from room n
else
if(oneLine.substring(0,1).equals("s")&&oneLine.substring(1,2).equals("s"))
{
System.out.println("status of orders from room n");
int roomno=Integer.parseInt(oneLine.substring(2,3));
DAOOrder daoOrder = new DAOOrder(whichDatabase);
if(daoOrder.isOrderDone(Integer.toString(roomno)))
{
System.out.println("Your order is completed");
}
else
{
System.out.println("Your order is not completed");
}
}
//baker reports pizza done
else
if(oneLine.substring(0,1).equals("b")&&oneLine.substring(1,2).equals("p")&&
oneLine.substring(2,3).equals("d"))
{
System.out.println("baker reports pizza done");
DAOBaker daoBaker = new DAOBaker("1",whichDatabase);
daoBaker.cookOrders();
}
//admin status report for today
else
if(oneLine.substring(0,1).equals("a")&&oneLine.substring(1,2).equals("s")&&
oneLine.substring(2,3).equals("t"))
{
System.out.println("admin status report for today");
}
//baker reports day is done
else
if(oneLine.substring(0,1).equals("b")&&oneLine.substring(1,2).equals("d")&&
oneLine.substring(2,3).equals("d"))
{
System.out.println("baker reports day is done");
DAOBaker daoBaker = new DAOBaker("2",whichDatabase);
daoBaker.endDay();
}
//generate admin college report on completed days since
last such report
else
if(oneLine.substring(0,1).equals("a")&&oneLine.substring(1,2).equals("c")&&
oneLine.substring(2,3).equals("r"))
{
System.out.println("generate admin college report on
completed days since last such report");
}
}
}
catch( IOException e )
{
System.out.println( e );
}
finally
{
// Close the stream
try
{
if(fileIn != null )
fileIn.close( );
}
catch( IOException e )
{ }
}
}
public static void main( String [ ] args )
{
String fileName="c:\\Documents and Settings\\"+
"Scott Spiegler\\workspace\\PizzaShop\\business layer test.txt";
readFile( fileName );
}
}

Andrea Desole

unread,
Oct 5, 2005, 12:18:38 PM10/5/05
to

Uncle Scotty wrote:
> I discovered one error. I was using the unix ':' from the command line
> rather than the Windows ';', when I told java about the classpath for
> the jar. Now, it runs as expected. The only question is how do I
> straighten out Eclipse so that it does what I want it to?

You first post is not completely clear to me, but if I understand
correctly you did the right thing: Run->Debug, Java Application, new,
and then set the main class. When you have created a new debugger just
click on apply and then debug. Make sure that the classpath is correct
Another possibility is: open the file with your main, and go to
Run->Debug As-> Java Application
I have never had problems with that, but it can still be a bug in Eclipse.

Uncle Scotty

unread,
Oct 5, 2005, 12:33:40 PM10/5/05
to
Weird, I did what you suggested by creating a new configuration rather
than just updating an existing one. And, it worked! :-0 I used all the
same settings as the one that didn't work, but this new one works and
the old one doesn't.

Any idea why?

Andrea Desole

unread,
Oct 5, 2005, 1:12:06 PM10/5/05
to

you mean a new debug configuration?Are you sure the settings are the
same? Did you check the classpath?
Or maybe you mean a new workspace/project/class?

Uncle Scotty

unread,
Oct 5, 2005, 1:23:05 PM10/5/05
to
I think I mean a new debug configuration. All I did was say Run->Debug,
and the window comes up that allows you to create, manage and run
configurations. And, with the configuration, called Test that I was
having all these problems with hilited, I clicked on the New button,
which seems to have assigned the same settings to my new configuration,
System Test. I know it doesn't seem right, but when I look in the
classpath tab, the UserEntry is set to my PizzaShop (default) folder. I
am pretty sure that is the way Test was setup too.

Does this make any sense? All I know is now I am not getting that
couldn't find class def error and I can run my app in debug mode! I'd
like to know what made this happen, for the next time I run across this
problem and as a way of understanding Eclipse better.

Andrea Desole

unread,
Oct 5, 2005, 1:34:44 PM10/5/05
to

Uncle Scotty wrote:
> I think I mean a new debug configuration. All I did was say Run->Debug,
> and the window comes up that allows you to create, manage and run
> configurations. And, with the configuration, called Test that I was
> having all these problems with hilited, I clicked on the New button,
> which seems to have assigned the same settings to my new configuration,
> System Test. I know it doesn't seem right, but when I look in the
> classpath tab, the UserEntry is set to my PizzaShop (default) folder. I
> am pretty sure that is the way Test was setup too.

I am not sure about that. I just tried (I have 3.2 M2) and the settings
don't appear to be copied. The classpath is definitely different.
What I get, though, is that the new debugger configuration takes the
classpath of the project it refers to (the one shown in the "Main" tab),
which is probably enough for both configurations


>
> Does this make any sense? All I know is now I am not getting that
> couldn't find class def error and I can run my app in debug mode! I'd
> like to know what made this happen, for the next time I run across this
> problem and as a way of understanding Eclipse better.

no, that looks strange. But Eclipse is not perfect, so it's possible.
If the configurations are really the same I don't know what it can be. I
might suggest some "exotic" approaches, like looking at the lauch
configuration files in the eclipse directory, but I would leave it as it is.
Also, if you are really interested, consider joining the eclipse newsgroups:

http://eclipse.org/newsgroups/index.html

0 new messages