NoClassDeffounderror

I am very new to java,

I am getting the following errrors for almost allthe programs i type..

error:exception in thread"main" java.def.NoClassDeffounderror:table1

where table1 is the name of the file.

here is the program :

import java.io.*;

import java.lang.*;

class table1 extends Thread

{

int m,n,i,sum;

public void getData(int X1)throws IOException

{

DataInputStream din=new DataInputStream(System.in);

System.out.println("enter the table no1");

m=Integer.parseInt(din.readLine());

n=X1;

}

public void run()

{

for(i=1;i<=n;i++)

{

sum=i*m;

System.out.print(i+"*"+m+"="+sum+"\t");

yield();

}

}

}

class table2 extends Thread

{

int m1,n1,j,sum1;

public void getData1(int X1)throws IOException

{

DataInputStream din=new DataInputStream(System.in);

System.out.println("enter the table no2");

m1=Integer.parseInt(din.readLine());

n1=X1;

}

public void run()

{

for(j=1;j<=n1;j++)

{

sum1=j*m1;

System.out.print(j+"*"+m1+"="+sum1);

System.out.println("");

yield();

}

}

}

when i try executing it.. i get this error:

class multi is public, should be declared in a file named multi.java

when i further try to execute it by using java table1.. i get the following error:

exception in thread"main" java.def.NoClassDeffounderror:table1

i do not know where i am going wrong.. I use DOS for execution.. i have saved the files in the following loacation: program files/java/jdk1.6.0_01/bin

and i type javac filename.classand then java filename

this worked for some programs like this one:

import java.io.*;

import java.lang.*;

import java.lang.String.*;

class Matrix

{

public static void main(String args[])throws IOException

{

try

{

int a[][],b[][],c[][],i,j,r1,r2,c1,c2,k=0;

a=new int[10][10];

b=new int[10][10];

c=new int[10][10];

DataInputStream din=new DataInputStream(System.in);

System.out.println("Enter first matrix row,col");

r1=Integer.parseInt(din.readLine());

c1=Integer.parseInt(din.readLine());

System.out.println("Enter second matrix row,col");

r2=Integer.parseInt(din.readLine());

c2=Integer.parseInt(din.readLine());

if(c1==r2)

{

System.out.println("enter the first matrix:");

for(i=0;i<=r1;i++)

{

for(j=0;j<=r1;j++)

a[j]=Integer.parseInt(din.readLine());

}

System.out.println("enter the second matrix");

for(i=0;i<r2;i++)

{

for(j=0;j<=c2;j++)

b[j]=Integer.parseInt(din.readLine());

}

for(i=0;i<=r1;i++)

{

for(j=0;j<=c2;j++)

{

c[j]=0;

for(k=0;k<r2;k++)

{

c[j]=c[j]+a[k]*b[k][j];

}

}

}

System.out.println("\t Resultant matrix:");

for(i=0;i<r2;i++)

{

for(j=0;j<c2;j++)

System.out.print(c[j]+"");

System.out.print("");

}

}

else

throw new IllegalAccessException("demo");

}

catch(Exception e)

{

System.out.println("illegal rows and cols");

}

}

}

but it is giving errors for some programs like this first one..can you please help

thankyou

>

[3541 byte] By [shw123a] at [2007-11-27 3:04:40]
# 1
I'm also pretty new to Java, but I think you forgot to declare the "main"- Method in your code. As far as I know, only classes with a "main"-method can be executed by the Java-VM.I didn't see this line in your code:public static void main(String args[])
Sapporilloa at 2007-7-12 3:49:22 > top of Java-index,Java Essentials,New To Java...
# 2

You will get the NoClassDef Exception. Because in your code no main method exists.

If you want to run your program , it should have a main method

import java.io.*;

import java.lang.*;

class table1 extends Thread

{

int m,n,i,sum;

public static void main(String[] args) {

//TODO

}

public void getData(int X1)throws IOException

{

DataInputStream din=new DataInputStream(System.in);

System.out.println("enter the table no1");

m=Integer.parseInt(din.readLine());

n=X1;

}

public void run()

{

for(i=1;i<=n;i++)

{

sum=i*m;

System.out.print(i+"*"+m+"="+sum+"\t");

yield();

}

}

}

I guess your multi.java has the main method but you did not declare the file with public access specifier.

AnanSmritia at 2007-7-12 3:49:22 > top of Java-index,Java Essentials,New To Java...
# 3

I am sorry i dint paste the last part of the program..:

public class multi

{

public static void main(String args[])throws IOException

{

int n;

DataInputStream din=new DataInputStream(System.in);

table1 obj1=new table1();

table2 obj2=new table2();

System.out.println("Enter how many rows?");

n=Integer.parseInt(din.readLine());

obj1.getData(n);

obj2.getData1(n);

obj1.start();

obj2.start();

}

}

so the whole program is:

import java.io.*;

import java.lang.*;

class table1 extends Thread

{

int m,n,i,sum;

public void getData(int X1)throws IOException

{

DataInputStream din=new DataInputStream(System.in);

System.out.println("enter the table no1");

m=Integer.parseInt(din.readLine());

n=X1;

}

public void run()

{

for(i=1;i<=n;i++)

{

sum=i*m;

System.out.print(i+"*"+m+"="+sum+"\t");

yield();

}

}

}

class table2 extends Thread

{

int m1,n1,j,sum1;

public void getData1(int X1)throws IOException

{

DataInputStream din=new DataInputStream(System.in);

System.out.println("enter the table no2");

m1=Integer.parseInt(din.readLine());

n1=X1;

}

public void run()

{

for(j=1;j<=n1;j++)

{

sum1=j*m1;

System.out.print(j+"*"+m1+"="+sum1);

System.out.println("");

yield();

}

}

}

public class multi

{

public static void main(String args[])throws IOException

{

int n;

DataInputStream din=new DataInputStream(System.in);

table1 obj1=new table1();

table2 obj2=new table2();

System.out.println("Enter how many rows?");

n=Integer.parseInt(din.readLine());

obj1.getData(n);

obj2.getData1(n);

obj1.start();

obj2.start();

}

}

the code public static void main(String args[]) is there in the public class multi..

shw123a at 2007-7-12 3:49:22 > top of Java-index,Java Essentials,New To Java...
# 4

public class multi

{

public static void main(String args[])

{

try {

int n;

DataInputStream din=new DataInputStream(System.in);

table1 obj1=new table1();

table2 obj2=new table2();

System.out.println("Enter how many rows?");

n=Integer.parseInt(din.readLine());

obj1.getData(n);

obj2.getData1(n);

obj1.start();

obj2.start();

} catch(Exception e) {

SOP(e.getMessage());

}

}

}

AnanSmritia at 2007-7-12 3:49:22 > top of Java-index,Java Essentials,New To Java...
# 5
I tried the code but then it gives the following error: class multi is public,should be declared in a file named mulit.javaplus it gives this error too:cannot find symbolsymbol:method SOP(java.lang.string)location:class multiSOP(e.getMessage());
shw123a at 2007-7-12 3:49:22 > top of Java-index,Java Essentials,New To Java...
# 6

Well from the book where i copied this code.. the following was written before the start of the program:

Step1: class tab1 which is the subclass of Thread

data members-m,n,i,sum

Override run Method which prints the multiplication table

Step2 class tab2 which is the subclass of Thread

data members-m,n,i,sum

Override run Method which prints the multiplication table

step3:In main class create object for tab1 and tab2

step5:start the threads

I do not knw how to do this exactly with the given program.can you help

shw123a at 2007-7-12 3:49:22 > top of Java-index,Java Essentials,New To Java...
# 7
i guess , you have misunderstood the line.SOP stands for System.out.println(e.getMessage());try the following command in your command window.javac multi.java if you get any error post your full error message. Your program works in my system
AnanSmritia at 2007-7-12 3:49:22 > top of Java-index,Java Essentials,New To Java...
# 8

Oh yes i dint understand that:) .. now after the correction made.. i tried the command you mentioned:javac multi.java

i get the following errors:

multi.java:3:cannot find symbol

symbol:class IOException

location:class multi

DataInputStream din=new DataInputStream(System.in);[there is a upper arrow mard below the D of the DataInputStream]

\table1.java :48:class multi is public,shoudl be declared in the file named multi.java

public class multi[there is an upper arrow uncer "c" of class multi]

note:.\table1.java uses or overrides a depriciated API

note:recomplie with -XLint:depreciation for details.

4 errors

shw123a at 2007-7-12 3:49:22 > top of Java-index,Java Essentials,New To Java...
# 9

i have reformatted your code below. try the following

table1.java

import java.io.*;

import java.lang.*;

class table1 extends Thread

{

int m,n,i,sum;

public void getData(int X1)throws IOException

{

DataInputStream din=new DataInputStream(System.in);

System.out.println("enter the table no1");

m=Integer.parseInt(din.readLine());

n=X1;

}

public void run()

{

for(i=1;i<=n;i++)

{

sum=i*m;

System.out.print(i+"*"+m+"="+sum+"\t");

yield();

}

}

}

table2.java

import java.io.DataInputStream;

import java.io.IOException;

class table2 extends Thread

{

int m1,n1,j,sum1;

public void getData1(int X1)throws IOException

{

DataInputStream din=new DataInputStream(System.in);

System.out.println("enter the table no2");

m1=Integer.parseInt(din.readLine());

n1=X1;

}

public void run()

{

for(j=1;j<=n1;j++)

{

sum1=j*m1;

System.out.print(j+"*"+m1+"="+sum1);

System.out.println("");

yield();

}

}

}

multi.java

import java.io.DataInputStream;

import java.io.IOException;

public class multi

{

public static void main(String args[])throws IOException

{

int n;

DataInputStream din=new DataInputStream(System.in);

table1 obj1=new table1();

table2 obj2=new table2();

System.out.println("Enter how many rows?");

n=Integer.parseInt(din.readLine());

obj1.getData(n);

obj2.getData1(n);

obj1.start();

obj2.start();

}

}

Try the above code. and compile each file in command line using javac

AnanSmritia at 2007-7-12 3:49:22 > top of Java-index,Java Essentials,New To Java...
# 10
Thankyou so much .. now it executes! ill try the rest of the programs now..thankyou once again:)
shw123a at 2007-7-12 3:49:22 > top of Java-index,Java Essentials,New To Java...
# 11

Hi i have another problem come up with a program where i have to use inheritance:

the instructions told:

design a class named Account

Data members:accno,name,branch name and balance

methods: getdetails()

putdetails()

design a class named Transaction which extends from the class Account data members: ttype,amount and cur_bal

methods: doTransaction()

printAll()

in the main method,create and object for the class Transaction and call the methods

what i did was:

created Account.java:

import java.io.*;

class Account

{

int acc_no;

String name;

String branch_name;

protected float old_bal;

protected static DataInputStream din=new DataInputStream(System.in);

void get_details()throws IOException

{

System.out.print("Enter Name:");

name=din.readLine( );

System.out.print("Enter Account no");

acc_no=Integer.parseInt(din.readLine());

System.out.print("Enter Branch Name.:");

branch_name=din.readLine( );

do

{

System.out.print("Enter Balance Amount(minimum2000):");

old_bal=Float.parseFloat(din.readline( ));

}

while(old_bal<=2000);

}

void put_details()

{

System.out.println("state Bank of india");

System.out.println("Chidambaram");

System.out.println("-");

System.out.println("AccountNo.:"+acc_no);

System.out.println("Name :"+name);

System.out.println("Branch name:"+branch_name);

System.out.println("oldBalance:"+old_bal);

}

}

created Transaction.java:

import java.io.DataInputStream;

import java.io.IOException;

class Transaction extends Account

{

String ttype;

float amount,cur_bal;

void Do Transaction()throws IOException

{

System.out.print("Enter Transaction code(D04-Deposit,W04-Withdraw:");

ttype=din.readLine();

System.out.print("Enter Transaction Amount:");

amount=Float.parseFloat(din.readLine());

if(ttype.equalsIgnoreCase("D04"))

cur_bal=old_bal+amount;

elseif(ttype.equalsIgnoreCase("W04"))

if(old-bal-amount>=2000)

cur_bal=old_bal-amount

else

{

System.out.println("Minimum amount must be 2000");

cur_bal=old_bal;

}

else

System.out.println("Invalid Transition");

cur_bal=old_bal;

}

}

void print All()

{

put_details();

if(cur_bal==old_bal)

System.out.println("No transactions");

else

{

System.out.println("Transaction Type:"+ttype);

System.out.println("Transaction amount:"+amount);

System.out.println("Current Balance:"+cur_bal);

}

}}

then created Bank.java:

import java.io.DataInputStream;

import java.io.IOException;

public class Bank

{

public static void main(String args[])throws IOException

{

Transaction T =new Transaction();

T.get_details();

T.do Transaction();

T.printAll();

}

}

and then complied each of them.. but am getting erors:

for bank.java i get:

identifier expected

T.do Transaction();[ iget an upper arrow mark below "d" and after the ";"]

for Account.java i get:

cannot find symbol:method readLine()

i get an upper arrow mark just below the dot of (din.readline( ));

and i get lots of errors in Transaction

can you help

shw123a at 2007-7-12 3:49:22 > top of Java-index,Java Essentials,New To Java...
# 12

Your method name is Do Transaction, but you have called T.do Transaction();. It is not a good practice for giving names. I have modified your method name in the following code snippet

void doTransaction()throws IOException // here i have changed the method name

{

System.out.print("Enter Transaction code(D04-Deposit,W04-Withdraw:");

ttype=din.readLine();

System.out.print("Enter Transaction Amount:");

amount=Float.parseFloat(din.readLine());

if(ttype.equalsIgnoreCase("D04"))

cur_bal=old_bal+amount;

elseif(ttype.equalsIgnoreCase("W04"))

if(old-bal-amount>=2000)

cur_bal=old_bal-amount

else

{

System.out.println("Minimum amount must be 2000");

cur_bal=old_bal;

}

else

System.out.println("Invalid Transition");

cur_bal=old_bal;

}

}

Use code tags next time

AnanSmritia at 2007-7-12 3:49:22 > top of Java-index,Java Essentials,New To Java...
# 13

or Account.java i get:

cannot find symbol:method readLine()

i get an upper arrow mark just below the dot of (din.readline( ));

You have written

old_bal=Float.parseFloat(din.readline( ));

readline should be readLine()

I found few errors in your Transaction.java. I have modified the file below

class Transaction extends Account

{

String ttype;

float amount,cur_bal;

void doTransaction()throws IOException

{

System.out.print("Enter Transaction code(D04-Deposit,W04-Withdraw:");

ttype=din.readLine();

System.out.print("Enter Transaction Amount:");

amount=Float.parseFloat(din.readLine());

if(ttype.equalsIgnoreCase("D04")) {

cur_bal=old_bal+amount;

} else if(ttype.equalsIgnoreCase("W04")) {

if((old_bal-amount) >= 2000)

cur_bal=old_bal - amount;

else

{

System.out.println("Minimum amount must be 2000");

cur_bal=old_bal;

}

} else {

System.out.println("Invalid Transition");

cur_bal=old_bal;

}

}

void printAll()

{

put_details();

if(cur_bal==old_bal)

System.out.println("No transactions");

else

{

System.out.println("Transaction Type:"+ttype);

System.out.println("Transaction amount:"+amount);

System.out.println("Current Balance:"+cur_bal);

}

}}

.

The changes are obvious so you dont need any explanation for these changes.

Use code tags next time.or read Formatting tips before posting your question

AnanSmritia at 2007-7-12 3:49:22 > top of Java-index,Java Essentials,New To Java...