LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-23-2008, 01:40 AM   #1
LinuxNewbie999
Member
 
Registered: Oct 2006
Distribution: FreeBSD
Posts: 162

Rep: Reputation: 30
Exception in thread "main" java.lang.NoClassDefFoundError:


Here is my code.
Code:
import java.io.*;
class Ex13{
    public static void main(String args[]) throws IOException{
        BufferedReader keyboard = new BufferedReader (new InputStreamReader(System.in));
       
        String input;
        int num = 0;
        int sum = 0;
       
        do {
        System.out.print("Enter a positive number: ");
        input = keyboard.readLine();
        num = Integer.parseInt(input);
       
        if ( num > 0)
            sum += num;
           
        }while (num > 0);
    System.out.println(sum);
    }
}
Compiling with javac hh.java was fine but somehow i got this error while run as java hh
Code:
Exception in thread "main" java.lang.NoClassDefFoundError: hh
   at gnu.j
ava.lang.MainThread.run(MainThread.java:102)
Caused by: java.lang.ClassNotFoundException: hh not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
   at java.net.URLClassLoader.findClass(URLClassLoader.java:529)
   at gnu.gcj.runtime.SystemClassLoader.findClass(natSystemClassLoader.cc:27)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:442)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:377)
   at gnu.java.lang.MainThread.run(MainThread.java:98)
Hmmmm.. what went wrong? How do i fix it??

Last edited by LinuxNewbie999; 03-23-2008 at 01:41 AM.
 
Old 03-23-2008, 04:42 AM   #2
duryodhan
Senior Member
 
Registered: Oct 2006
Distribution: Slackware 12 Kernel 2.6.24 - probably upgraded by now
Posts: 1,054

Rep: Reputation: 46
The class containing main function needs to be public
 
Old 03-24-2008, 12:12 AM   #3
LinuxNewbie999
Member
 
Registered: Oct 2006
Distribution: FreeBSD
Posts: 162

Original Poster
Rep: Reputation: 30
hmmm, thank you. After i change the java file name same as the public class, it works.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception in thread "main" java.lang.ClassFormatError: onmyown.Main (unrecognized cla zimboney Fedora 4 07-20-2007 01:00 PM
Exception in thread "main" java.lang.UnsupportedClassVersionError manolakis Programming 2 01-20-2007 10:56 AM
Java error "Exception in thread "main" java.lang.StackOverflowError" nro Programming 1 09-04-2004 03:47 AM
Exception in thread "main" java.lang.NoClassDefFoundError: Lobais Linux - Software 19 06-23-2004 08:42 AM
Exception in thread "main" java.lang.NoClassDefFoundError: melinda_sayang Programming 2 04-27-2004 11:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration