• Post Reply Bookmark Topic Watch Topic
  • New Topic

I'm having trouble with running Java  RSS feed

 
Jackii Jonsen
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I'm a beginner for java.

I just finishied writing one simple program..checking with Javac if there is any errors. And..I tried to run the program. But..it keeps giving me
one error message that says " Exception in thread "main" java.lang.NoClassDefFoundError: c:\java2\Stack3"


And the program I wrote is the program that determin if a phrase is a palindrome, using Stack. Ex> MADAM, BOB


import java.util.*;

public class Stack3
{
public static void process(String str, Stack stack)
{
String placeholder = new String("");
String strCompare = new String("");
int intspace = 0;
String strNoSpaceCompare = new String("");
for (int intcount = 0; intcount < str.length(); intcount++)
{
placeholder = new String(str.substring(intcount, intcount+1));
if (placeholder.equals(" "))
{
intspace++;
if (intspace==1)
for (int intcount2 = 0; intcount2<str.length(); intcount2++)
{
placeholder = str.substring(intcount2, intcount2 + 1);
if (!placeholder.equals(" "))
strNoSpaceCompare = strNoSpaceCompare.concat(placeholder);
}
}
else
stack.push(placeholder);
}

if (intspace==0)
{
while (!stack.isEmpty())
strCompare = strCompare.concat((String) stack.pop());
if (strCompare.equals(str))
{
System.out.print(str);
System.out.println(" is a palindrome");
}
else
{
System.out.print(str);
System.out.println(" is not a palindrome");
}
}
else
{
while (!stack.isEmpty())
strCompare = strCompare.concat((String) stack.pop());
if (strNoSpaceCompare.equals(strCompare))
{
System.out.print(str);
System.out.println(" is a palindrome");
}
else
{
System.out.print(str);
System.out.println(" is not a palindrome");
}
}
}

public static void main (String[] args)
{
String str1 = new String("BOB");
String str2 = new String("RADAR");
String str3 = new String("A MAN A PLAN A CANAL PANAMA");
String str4 = new String("RACECAR");
Stack One = new Stack();
process( str1, One);
process( str2, One);
process( str3, One);
process( str4, One);
}
}
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to set the class path, here is how.
 
Jackii Jonsen
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, thank you for answering...

but..I couldn't get it worked...I cannot find out how to do this..

can you show me how to do set this...like..in a more simple way?

I try to type

"c:\>java -classpath c:\java2" <-- "java2" is the folder that I saved
my java files.

and it doesn't work...
 
Jackii Jonsen
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OH..by the way, I get two notes when I uses "javac" ..

: notes: c:\java2\Stack3.java uses unchecked or unsafe operations.
notes: recompile with -xlint: unchecked for details
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After you compile run using the following command:

>> java -cp . Stack3

The dot indicates that the JVM should look for the classes in your current path.

To avoid using the (-cp .) flag each time you run a java application, set the classpath in your Environment Variable window:
  • Open the EV window
  • Create a variable named "CLASSPATH"
  • Add . as a value
  • Open a new command window and try to run the application again


  • OH..by the way, I get two notes when I uses "javac" ..

    : notes: c:\java2\Stack3.java uses unchecked or unsafe operations.
    notes: recompile with -xlint: unchecked for details


    I haven't gone through your code, but this warning indicates that your code could be written in a better way. The class file should have been generated successfully nevertheless, and you should be able to run it using the previous command.
     
    Jackii Jonsen
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you for your advice, Vicken. But...sorry to say..I don't get it.
    I tried things that I think you tried to tell me to do, but..it didn't work out...I think I just didn't udenrstand your explanation enough..
    What is EV window? and...what am I supposed to put on the DOS prompt?
    "classpath" this command doesn't work..it keeps showing me errors.
    I'm sorry to bother you so much. But..could you show me the steps to get it worked in detail?..like..um..

    Step 1 : put #%@!%!$ on Dos prompt
    Step 2 : do #@%!25!@#$%@!#5 ..

    like this..I'm sorry and Thank you so much.
     
    Vicken Karaoghlanian
    Ranch Hand
    Posts: 522
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Okay, let me try again. First of all let us make sure that you can compile and run the above posted code and then i'll explain how to add the classpath to you "Environment Variables" section.

    On the command prompt do the following:

    1) Compile your application
    >> javac Stack3.java
    This will generate a class called "Stack3.class"

    2) Run your application
    >> java -cp . Stack3

    Try these commands and let me know what happens.
    [ January 09, 2005: Message edited by: Vicken Karaoghlanian ]
     
    Jackii Jonsen
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Oh~~!!! It works!!!

    Thank You So~~~much~!!!

    Oh..by the way..I'm having many other troubles, trying to do a few other programs...Can I ask you those things personally, using e-mail? Oh...just only if you enjoy helping others and you are not busy...
    I'm really sorry to bother you..but..you know.. others in this forum are not kind and specific like you..So..
    If you think you could have some time to help me out, please leave your e-mail address. I will really appreciate it. Thank you.
     
    Marilyn de Queiroz
    Sheriff
    Posts: 9082
    12
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Welcome to Javaranch, Jackii. I'm glad that someone was able to help you. I'm sure that as you continue to post that you will find very many people who are both willing and able to help you. This allows others with similar problems to also find help in the future (via searches, etc), and allows more than one person the opportunity to give of their expertise at the time they find most convenient. Please do not limit yourself to one kind and knowledgable person (assuming that that person has the time to tutor you one on one).

    Javaranch is all about sharing knowledge, and as you learn, perhaps you, too, will be able to help someone else.
    [ January 09, 2005: Message edited by: Marilyn de Queiroz ]
     
    Vicken Karaoghlanian
    Ranch Hand
    Posts: 522
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    others in this forum are not kind and specific like you


    I disagree; Javaranch contains the best and elite gurus in the business, some people at this forum are so good that make you wonder if one of them could be James Gosling in disguise.

    I've been in this forums for more than a year now, and let me tell you that I have never seen a people so kind and generous that they are willing to spare their own personal time to help and assist another person that they don't and probably will not meet.


    If you think you could have some time to help me out, please leave your e-mail address. I will really appreciate it


    There are a lot people in this forum that are far more knowledgeable than me and are willing to offer their help. If they didn't help you this time that doesn't mean that they won't the next time. Keep posting and you'll see what I am talking about.
     
    Jackii Jonsen
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Oh...sorry about late reply..I had trouble with internet..

    and..Thank you guys so much for regarding my message.

    I really appreciate you guys' advice ~ Thank you again.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!