Compiling .java files

P

peddie

Hi
I have a java file that I compiled and when used it in an application,
an error said that I could not call the class since it is not public.
Then I noticed that the some codes are declared as private, so I
changed them all to public then recompile. The error message still
persits that it is not public.

Did I do this right? Do I have to do something extra before
re-compiling the java file?

Am so new to this subject please kindly assist me

Thanks

Peddie
 
P

peddie

I tried to instantiate the java object inside a PeopleSoft application.
The error is a message box below.


Java Exception: java.lang.NoClassDefFoundError: finding class
PhoneticEye

I save the .class files in C:/Pt8.44/class/ which I have added this in
the CLASSPATH.

The java file that I compilied is below


public class PhoneticEye {

static {
System.loadLibrary( "PhoneticEye_jni" );
};

/**Native Method Definition*/
public static native void PE_Initialize();
public static native void PE_UnInitialize();
public static native void PE_SetThreshold( int threshold );
public static native String PE_GetSmartCode( String targetStr, int
mode );
public static native String[] PE_GetPhonemes( String targetStr, int
mode );

public static native int PE_Match_Str2Str( String matchStr, String
targetStr, int type, int mode );
public static native int PE_Match_Ph2Str( String[] phonemes, int
phonemesSize, String targetStr, int type, int mode );
public static native int PE_Match_Ph2Ph( String[] matchPhonemes,
int matchPhSize, String[] targetPhonemes, int targetPhSize, int type,
int mode );
public static native StringMatch[] PE_Match_Str2List( String
matchStr, String[] targetStrList, int listSize, int type, int mode );

// PE MODES
public static final int PE_MODE_ENGLISH = 0;
public static final int PE_MODE_NONENGLISH = 1;

// PE TYPES
public static final int PE_TYPE_OR = 0;
public static final int PE_TYPE_AND = 1;
public static final int PE_TYPE_AND_TRANSPOSED = 2;
public static final int PE_TYPE_EXACT = 3;


PhoneticEye() {}

void Initialize() {
PE_Initialize();
}

void UnInitialize() {
PE_UnInitialize();
}

void SetThreshold( int threshold ) {
PE_SetThreshold( threshold );
}

String GetPESmartCode( String targetStr, int mode ) {
return PE_GetSmartCode( targetStr, mode );
}

String[] GetPhonemes( String targetStr, int mode ) {
return PE_GetPhonemes( targetStr, mode );
}

int Match_Str2Str( String matchStr, String targetStr, int type, int
mode ) {
return PE_Match_Str2Str( matchStr, targetStr, type, mode );
}

int Match_Ph2Str( String[] phonemes, String targetStr, int type,
int mode ) {
return PE_Match_Ph2Str( phonemes, phonemes.length, targetStr,
type, mode );
}

int Match_Ph2Ph( String[] matchPhonemes, String[] targetPhonemes,
int type, int mode ) {
return PE_Match_Ph2Ph( matchPhonemes, matchPhonemes.length,
targetPhonemes, targetPhonemes.length, type, mode );
}

StringMatch[] Match_Str2List( String matchStr, String[]
targetStrList, int type, int mode ) {
return PE_Match_Str2List( matchStr, targetStrList,
targetStrList.length, type, mode );
}

}

class StringMatch {
public String targetStr;
public int simValue;
public StringMatch(){
targetStr = "";
simValue = 0;
}
}
 
O

Oliver Wong

peddie said:
Hi
I have a java file that I compiled and when used it in an application,
an error said that I could not call the class since it is not public.
Then I noticed that the some codes are declared as private, so I
changed them all to public then recompile. The error message still
persits that it is not public.

Did I do this right? Do I have to do something extra before
re-compiling the java file?

Am so new to this subject please kindly assist me

Thanks

Is the class itself declared public?

<code>
public class Foo {
private int x;
}
</code>

In this example code I just posted, the class itself, Foo, is public, even
though one of its fields, x, is private.

You also have to make sure that the name of the class is the same as the
name of the file, with the extra ".java" extension. So you MUST save the
above code in a file called "Foo.java" to compile it. If you name it
something else, like "Bar.java", it won't compile properly.

- Oliver
 
Y

youri lima

Java Exception: java.lang.NoClassDefFoundError: finding class
PhoneticEye

this error is the wrong filename error because when calling a class it
searches for files with that name before actually looking in the file
 
Y

youri lima

Java Exception: java.lang.NoClassDefFoundError: finding class
PhoneticEye

this error is the wrong filename error because when calling a class it
searches for files with that name before actually looking in the file
 
P

peddie

Hi Oliver
The name is all the same. In fact I have downloaded these files from
PhoneticEye website (the supplier that provides the fuzzy search
facility). I try to use this on PeopleSoft application.
The class called PhoneticEye and all relevant files too.
So with your theory, tho the fields are private, this should work then
but I dont know why it didnt work.

Now I try to compile the java file with command line. It gives me the
error Exception in thread "main" java.lang.NoClassDefFoundError:
PhoneticEye/Java

If I use javac command line it didnt give me an error message and a
class file is created. Whats the difference between java and javac?
Thanks a lot
Peddie
 
O

Oliver Wong

peddie said:
Hi Oliver
The name is all the same. In fact I have downloaded these files from
PhoneticEye website (the supplier that provides the fuzzy search
facility). I try to use this on PeopleSoft application.
The class called PhoneticEye and all relevant files too.
So with your theory, tho the fields are private, this should work then
but I dont know why it didnt work.

Now I try to compile the java file with command line. It gives me the
error Exception in thread "main" java.lang.NoClassDefFoundError:
PhoneticEye/Java

If I use javac command line it didnt give me an error message and a
class file is created. Whats the difference between java and javac?
Thanks a lot
Peddie

"javac" is the program which compiles a java programs, while "java" is the
program which actually runs the program. If the file ends in ".java", it's
probably a java source code file, which is intended to be read by humans and
not by computers. If the file ends in ".class", it's probably a java class
file, which is intended ot be run by computers and not read by humans.

So the appropriate steps are:

(*) Download the ".java" file from the website.
(*) Optionally inspect them and make modifications to them if you want.
(*) Run "javac" on the ".java" file to generate a ".class" file.
(*) Run "java" on the ".class" file to actually run the program.

In that last step, when you run "java", make sure not to include the
".class" extension. So if you wanted to run the program in the file
"Foo.class", you would type in "java Foo", and not "java Foo.class".

- Oliver
 
Joined
Nov 17, 2008
Messages
1
Reaction score
0
set classpath=%CLASSPATH%;.;

run that command in command line before compiling ur java programs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top