• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception in thread

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)?
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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++;
}
}

}
 
This tiny ad is suggesting that maybe she should go play in traffic.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic