Please help me. I am getting a runtime error.

Package problem in java?

Please help me. I have two packages named app and Util. Util is inside app. In Util i have the file BitUtils.java and in app i have CertkillerApp.java which is the driver file. I am getting error. Please help me.

BitUtils.java :

package Util;

public class BitUtils {

public static void process(new byte[]) {

System.out.println("Inside method byte");

}

}

CertkillerApp.java

package app;

public class CertkillerApp {

public static void main(String[] args) {

byte[] bytes = new byte[256];

Util.BitUtils.process(bytes);

}

}

Now when i am entering app directory inside D: by cd app and compling by javac CertkillerApp.java. It is compiling but when i am executing from the same directory it is

giving runtime errror.

Output :

D:\APP>java app.CertkillerApp

Exception in thread "main" java.lang.NoClassDefFoundError... app/CertkillerApp

[991 byte] By [Tatona] at [2007-10-3 2:53:48]
# 1
Try:java-classpathD:\app.CertkillerAppAnd please read: [url http://java.sun.com/j2se/1.3/docs/tooldocs/solaris/classpath.html]Setting the class path[/url].Regards
jfbrierea at 2007-7-14 20:42:52 > top of Java-index,Java Essentials,New To Java...
# 2
Try running the command from D:\ instead of D:\App .Or use "set CLASSPATH = %CLASSPATH%, D:\"
myjavasticka at 2007-7-14 20:42:52 > top of Java-index,Java Essentials,New To Java...
# 3
I tried both ways but it is not running.Please help me.
Tatona at 2007-7-14 20:42:52 > top of Java-index,Java Essentials,New To Java...
# 4
Taton - bringing you the finest in general ineptitude since August 4th 2006
cotton.ma at 2007-7-14 20:42:52 > top of Java-index,Java Essentials,New To Java...
# 5
> I tried both ways but it is not running.> Please help me.What exactly are you trying, and maybe you need to make sure that the directory name matches the package name, case 'n all...
CeciNEstPasUnProgrammeura at 2007-7-14 20:42:52 > top of Java-index,Java Essentials,New To Java...
# 6

I think I got it.

You said: "Util is inside app", right?

First: package names should allways be with lowercases.

So I would change it for: util.

Second: since the package util is "inside" the package app, then the real name of the package util is: app.util.

It is NOT just util (there is no such thing in Java as partial package names).

So you should have the following folders/files:

D:\

D:\app

D:\app\CertkillerApp.java

D:\app\util

D:\app\util\BitUtils.java

Where BitUtils.java file should start with:package app.util;

And CertkillerApp.java should look like:package app;

public class CertkillerApp {

public static void main(String[] args) {

byte[] bytes = new byte[256];

app.util.BitUtils.process(bytes);

}

}

Then you should compile them:cd D:\

javac -classpath . app\*.java app\util\*.java

Then run it:cd D:\

java -classpath . app.CertkillerApp

Regards

jfbrierea at 2007-7-14 20:42:52 > top of Java-index,Java Essentials,New To Java...
# 7
Compiling FineD:\>javac -classpath app\*.java app\util\*.javaNot runningD:\>java D:\app app.CertkillerAppException in thread "main" java.lang.NoClassDefFoundError: D:\appRegards TatonMessage was edited by: Taton
Tatona at 2007-7-14 20:42:52 > top of Java-index,Java Essentials,New To Java...
# 8

> Compiling Fine

>

> D:\>javac -classpath app\*.java app\util\*.java

>

> Not running

> D:\>java D:\app app.CertkillerApp

> Exception in thread "main"

> java.lang.NoClassDefFoundError: D:\app

Notice something? You forgot the -cp flag.

CeciNEstPasUnProgrammeura at 2007-7-14 20:42:52 > top of Java-index,Java Essentials,New To Java...
# 9
D:\>java -classpath D:\app app.CertkillerAppException in thread "main" java.lang.NoClassDefFoundError: app/CertkillerAppD:\>java -cp D:\app app.CertkillerAppException in thread "main" java.lang.NoClassDefFoundError: app/CertkillerAppRegardsTaton
Tatona at 2007-7-14 20:42:52 > top of Java-index,Java Essentials,New To Java...
# 10
Jeebus.
cotton.ma at 2007-7-14 20:42:52 > top of Java-index,Java Essentials,New To Java...
# 11
Taton,I must say. Your inability to follow simple instructions is quite remarkable. Do look at what you are doing and what jfbriere has told you several times now. Do you see a difference? Please god see a difference...
cotton.ma at 2007-7-14 20:42:52 > top of Java-index,Java Essentials,New To Java...
# 12
Watch the classpath.
CeciNEstPasUnProgrammeura at 2007-7-14 20:42:52 > top of Java-index,Java Essentials,New To Java...
# 13
Done. denotes current directory.Thanks all.
Tatona at 2007-7-14 20:42:52 > top of Java-index,Java Essentials,New To Java...
# 14
I always have this classpath problem.
Tatona at 2007-7-14 20:42:52 > top of Java-index,Java Essentials,New To Java...
# 15

Here's some info on classpath:

[url=http://wiki.java.net/bin/view/Javapedia/ClassPath ]Javapedia: Classpath[/url]

[url=http://java.sun.com/j2se/1.5.0/docs/tooldocs/findingclasses.html ]How Classes are Found[/url]

[url=http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html ]Setting the class path (Windows)[/url]

[url=http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/classpath.html ]Setting the class path (Solaris/Linux)[/url]

[url=http://www-106.ibm.com/developerworks/edu/j-dw-javaclass-i.html ]Understanding the Java ClassLoader[/url]

PhHeina at 2007-7-21 10:02:22 > top of Java-index,Java Essentials,New To Java...