Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Package

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

Started to study java for few weeks, doing some baby steps in JAVA. planning to take SCJP in June.
Need some help in Package, I can successfully compile the code, but at the time of running got the error message
package cert;
public class testdefault
{
public static void main (String args[])
{
B a1 = new B();
System.out.println(a1.a) ;
a1.print(a1.a);
}
}
class A
{
int a = 10;
public void print(int a)
{
System.out.println(" Super default value for a " +a );
}
}

class B extends A
{
public void print(int a)
{
System.out.println(" Subclass value a from A" +a );
}
}



Error Message

Exception in thread "main" java.lang.noclassdefdounderror :testdefault wrong name (cert/testdefault)
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where have you set your classpath to?

Is it pointing to the directory containing cert.

Also did you use java cert.testdefault to run the class?
[ March 02, 2007: Message edited by: Rachil Chandran ]
 
Sathya Shanmugam
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My directory is like this
c:/java/scjp/cert

In cert directory, I save that file testdefault.java
It has compiled without any errors,
but when I ran java testdefault, given the same error

If I am not using the package its running good.
but when I use the package its not running.

Also I don't know how to set the classpath
 
Rachil Chandran
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try

set classpath = c:/java/scjp;%CLASSPATH%

and then,

java cert.testdefault
 
Sathya Shanmugam
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rachil,

Now it is working.

When I set the classpath in c:\java\scjp, it works well

But When I set the classpath in c:\java\scjp\cert

then I was in C:\java\scjp\cert> java testdefault

its showing the same error again, Whats the reason.


I am really new to JAVA, so my questions might be silly
 
Squanch that. And squanch this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic