aspose file tools*
The moose likes Beginning Java and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread" Watch "Exception in thread" New topic
Author

Exception in thread

Mohd Zaki Mohd Salikon
Greenhorn

Joined: Dec 16, 2004
Posts: 27
Hi everybody...

I want to know, why this error happens:

1. Exception in thread "main" java.lang.NoSuchMethodError:
2. Exception in thread "main" java.lang.NoSuchMethodError: main
3. Exception in thread "main" java.lang.NoClassDefFoundError: Sort

The programs cannot give the output but it can compile. How to solve it?
Thanks...
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
The API documentation suggests that you recompiled the class containing the called method without also recompiling the class that calls the method. The error could also happen if you use reflection.

The issue is that these errors are normally caught by the compiler unless this kind of change happens.

Can you tell us more about what happened or post the code (with CODE tags to preserve your indentation)?


Mike Gershman
SCJP 1.4, SCWCD in process
Andris Jekabsons
Ranch Hand

Joined: Jan 20, 2004
Posts: 82
The error #2 usually occurs for the class that you want to run as the main class of your application, but have omitted the
"public static void main( String[] args )" method.

Sometimes it is also a matter of mistyping the main() method - either typed with a different return value, left out the "public static" part or given some other parameters.

Andris
[ January 16, 2005: Message edited by: Andris Jekabsons ]
Mohd Zaki Mohd Salikon
Greenhorn

Joined: Dec 16, 2004
Posts: 27
Hi...I was create the main function but it still cannot call the function. What the codes to call the Chromo function? I try to use this code:

krom[i] = new Chromo(subjek,nos);
krom[i].rawak(bilslot);

but it is error.

The full class is below:

import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import Data;

public class Chromo extends Frame {

public static int bilchrom = 0;
public int nos;
public String subjek[];
public int slot[];
public int jum_penalty = 0;
private int bil_slot;
int fit=0; double rfit; double cfit;

TextField[] tf ;
TextField tf2 = new TextField(9);
Button bkos = new Button("Jana Populasi");
Label lb = new Label("Fitness Kromosom ini: ");


Chromo(String subjek[],int nos) {

super("Kromosom Nombor: " + (++bilchrom));
this.nos=nos;
this.subjek = subjek;
initslot();
setlayout();
}

Chromo(String nama,String subjek[],int nos) {

super("Kromosom " +nama);
this.nos=nos;
this.subjek = subjek;
initslot();
setlayout();
}

void setlayout(){
setBackground(Color.lightGray);
tf = new TextField[nos];
Panel p = new Panel();
p.setLayout(new GridLayout(nos/3 + 1,3,10,5));

Panel p2 = new Panel();
p2.setLayout(new FlowLayout(FlowLayout.CENTER));
p2.add(lb);
tf2.setText(Integer.toString(fit));
p2.add(tf2);


int count=0;
while (count<nos) {
Panel fp = new Panel();
Label lb = new Label();
tf[count] = new TextField(""+slot[count]);
tf[count].setEditable(false);
fp.setLayout(new GridLayout(1,2,15,0));
lb.setText(subjek[count]);
fp.add(lb);
fp.add(tf[count]);
p.add(fp);
count++;
}

add(p,"North");
add(p2,"Center");

}

void initslot() {
short n=0;
slot = new int[nos];
while(n < nos) {
slot[n]= 0;
n++;
}
}

void kosongkan() {
short n=0;
while(n < nos) {
slot[n]= 0;
n++;
}
fit=0; rfit=0.0; cfit=0.0;
}

public void rawak(int bs){
Random gen = new Random();
int n=0;

slot = new int[nos];
gen.setSeed(System.currentTimeMillis());
while(n < nos) {
slot[n]= Math.abs(gen.nextInt() % bs) + 1;
tf[n].setText(Integer.toString(slot[n]));
n++;
}
}

public void setteks() {
int n=0;

while(n < nos) {
tf[n].setText(Integer.toString(slot[n]));
n++;
}
tf2.setText(Integer.toString(fit));
}

public String subjek(int gen) {

return subjek[gen];

}

public int nomslot(int gen) {

return slot[gen];
}

public void penalti(int p) {
fit -= p;
tf2.setText(Integer.toString(fit));

}

void setFitness(int f) {
fit = f;
tf2.setText(Integer.toString(fit));
}

int getFitness() {
return fit;
}

void rfitnessSet(double r) {
rfit = r;
}

void cfitnessSet(double c) {
cfit = c;
}

double rfitnessGet() {
return rfit;
}

double cfitnessGet() {
return cfit;
}

void copyChromosome(Chromo k) {
k.fit = fit;
k.rfit = rfit;
k.cfit = cfit;
for (int i = 0; i < nos; i++) {
k.slot[i]=slot[i];
k.setteks();
}
}

boolean samadgn(Chromo k) {
boolean sama=true;
if (k.fit != fit) return false;
for (int i = 0; i < nos; i++) {
if (k.slot[i]!=slot[i]) {
sama=false;
break;
}
}
return sama;
}

int Genke(int i){
return slot[i];
}

void setGenke(int i, int j) {
slot[i] = j;
tf[i].setText(Integer.toString(slot[i]));
}

public boolean handleEvent(Event e) {
if (e.id==Event.WINDOW_DESTROY) {
//System.exit(0);
hide();
dispose();
}
return super.handleEvent(e);
}

public static void main(String[] args) {
int bil_krom=50;
short i=0;
Chromo[] krom;

krom = new Chromo[bil_krom];
//best = new TChromo(this,"Terbaik",subjek,nos);
// sbest = new Vector(1,1);

while (i < bil_krom) {
// krom[i] = new Chromo(subjek,nos);
// krom[i].rawak(bilslot);
System.out.println("Menjanakan " + bil_krom + " kromosom...." + (i+1));
i++;
}
}

}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread
 
Similar Threads
Main Method
toString()?
Help me for these questions from John Hunt's mock exam
java.lang.NoSuchMethodError
can we develop java application without main method in jdk1.7?