Solved

Java problem(runing application)

Posted on 2002-05-07
13
391 Views
Last Modified: 2013-11-23
Hello,
  I just started using java and I´m using Textpad and j2sdk1.4.0. My problem begins with when ever I compile an applet I get this message that my applet is overriding or using a deprecated API("filename".java uses or overrides a deprecated API.) and I have almost tried evry thing that I can think of. My second problem lays in the application, I can compile it with no problems but when I try to run it I get this message in the dos-promt window "Exception in thread "main" java.lang.NoClassDefFoundError: Hallo
Press any key to continue . . ."

Can anyone help me please this is realy starting to bug me..
0
Comment
Question by:Doner
  • 4
  • 4
  • 2
  • +3
13 Comments
 
LVL 3

Expert Comment

by:rjackman
ID: 6995584
hi
>>I get this message that my applet is overriding or using a deprecated API("filename".java
uses or overrides a deprecated API.)

Just a warning won't harm but if u want to remove it then try and compile ur class with -deprecation option
ie
javac -deprecation yourjavafilename.java

>>>>I can compile it with no problems but when I try to run it I get this
message in the dos-promt window "Exception in thread "main" java.lang.NoClassDefFoundError

Check your code again I think u don't have main method in your code
main method is the main entry point for the jvm
it's syntax is predefined
public static void main(String []args)
{

}

cheers
RJ
0
 
LVL 2

Expert Comment

by:CSuvendra
ID: 6995687
Applets cannot be run with Java. Create a HTML file as

<!DOCTYPE HTML>
<HTML>
<HEAD></HEAD>
<BODY>
<APPLET CODE="Hallo.class" CODEBASE="." WIDTH=400 HEIGHT=300>
</APPLET>
</BODY>
</HTML>

Save as Hallo.html

Now run with

appletviewer Hallo.html

or using any browser.
0
 

Expert Comment

by:InSaNiE
ID: 6995750
If using textpad, create the html file as CSuvandra said above,and while in textpad press ctrl and 3 to 'run' the HTML file - this will open the html file and run the applet.
It's easier than having to type out 'appletviewer' all the time or having a browser open.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 7

Expert Comment

by:tomboshell
ID: 6995755
Just for further information (an accompanying comment) deprecation is what they mean when they are planning to drop that method/class.  Eventually it will dissappear (gone), and then your code that uses this aspect will no longer work.  However, at the time when it only states that it is deprecated it will still work.  Just be aware type of thing.  use the above mentioned compile options.  You can also define a new tool option in TextPad by selecting the menu Configure-Preferences.  Then select the Tool choice (don't pull down, select)  Click on the add button and choose a program.  Then browse through the directory until you find the javac compiler (usually in your bin directory :))  It will then appear in your selection of tools.  Now modifiy the parameters that will be sent to the tool.  Use the predefined Javac settings, but in the Parameters section include "-deprecation $File"   use the rest of the parameters like in the standard call to the Javac compiler.  Now you have a command configured to handle those pesky messages!

0
 

Expert Comment

by:selsted
ID: 6995971
Try writing:

java foobar

It will return with:
"Exception in thread "main" java.lang.NoClassDefFoundError: foobar"

So this is because it can't find your class file. If you are not using package in your java file, be sure that you are positioned at the correct place in you dos-prompt. If you are using package, you need to go to the root of your classpath, and write the package followed by the class name: java foo.bar.foobar

Since you state that you try to run the program in a dos-prompt, there is two things that you should be aware of. It is not an applet, these are run from within browsers, and you need to have a method:
public static void main(String[] strArgs)
in your java file.
0
 

Author Comment

by:Doner
ID: 6995978
class Hello
  {
    public static void main(String []args)
     {
       System.out.println("hello World");
     }
  }

this is the hello world program and I can´t get it to work I get the same message (Exception in thread "main" java.lang.NoClassDefFoundError: Hello
Press any key to continue . . .)



0
 

Author Comment

by:Doner
ID: 6995984
class Hello
  {
    public static void main(String []args)
     {
       System.out.println("hello World");
     }
  }

this is the hello world program and I can´t get it to work I get the same message (Exception in thread "main" java.lang.NoClassDefFoundError: Hello
Press any key to continue . . .)



0
 

Expert Comment

by:InSaNiE
ID: 6995991
If typing 'java Hello ' in dos, you have to be in the same directory as the java file. If the hello.java is stored in c:\java\prog1 you must change the dir in DOS to c:\java\prog1 then type 'javac Hello.java' to compile.
0
 

Expert Comment

by:InSaNiE
ID: 6996013
If typing 'java Hello ' in dos, you have to be in the same directory as the java file. If the hello.java is stored in c:\java\prog1 you must change the dir in DOS to c:\java\prog1 then type 'javac Hello.java' to compile.
0
 

Author Comment

by:Doner
ID: 6996015
Yes I know, I do not hava truble with compiling the .java file but runing the class file is the problem. After I have compiled the .java file and try to run it I get the message (Exception in thread
"main" java.lang.NoClassDefFoundError: Hello
Press any key to continue . . .)





0
 

Expert Comment

by:InSaNiE
ID: 6996039
is your java file named Hello.java - if it isn't that could be the problem.
0
 

Accepted Solution

by:
selsted earned 100 total points
ID: 6996055
I just tried copying your program into a Hello.java file, put it in my root, ran "javac Hello.java", and then "java Hello". Guess what, I got the same error.

I don't recall this being a problem earlier. It might be the new JVM's giving this problem.

The fix is easy, you need to add the dir in which the java file is stored to your classpath. This is done by the following:

"java -cp . Hello"

You can read more about setting classpath on the net.
0
 

Author Comment

by:Doner
ID: 6996325
This work.

using classpath in your Parameters( -Classpath . $BaseName)
or in dos "java -classpath Hello".

Thanks for the help.....
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
thymeleaf natural templating vs JSP 2 98
custom annotations 9 38
Windows 10 IE Certificate Issue 10 45
by zero exception 10 40
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question