Strona 1 z 1
Netbeans nie kompiluje prostej aplikacji SWING
: 24 lip 2011, 17:21
autor: kozio
Nie wiem czy dobrze umieściłem ten wątek ale chodzi o to, że Netbeans kompiluje programy a javie ale jeśli chodzi o Swing to
Exception in thread "main" java.lang.NoClassDefFoundError mam ten problem to tak jakby nie było biblioteki : /
Używam java6-sun, nie chce openjdk ;S
Czy ktoś by mógł podpowiedzieć coś?
Re: Netbeans nie kompiluje prostej aplikacji SWING
: 24 lip 2011, 18:33
autor: Semutachi
Coś.
A tak na serio to wklej kod tego programu co się nie kompiluje.
PS. Popraw swój post tak, aby dało się go odczytać.
Re: Netbeans nie kompiluje prostej aplikacji SWING
: 24 lip 2011, 18:56
autor: kozio
Weź NetBeansa i po prostu stwórz okno JFrame :S bez niczego 0 kodu, i normalnie na Windowsie się odpala a ja mam ten dziwny błąd : (
Re: Netbeans nie kompiluje prostej aplikacji SWING
: 24 lip 2011, 19:19
autor: Semutachi
Kod wygenerowany w całości przez NetBeans'a kompiluje się i działa poprawnie.
Kod: Zaznacz cały
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* NewJFrame.java
*
* Created on 2011-07-24, 19:12:10
*/
/**
*
* @author jedrzej
*/
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
// End of variables declaration
}
Działa również dużo prostszy kod z zetcode.com
Kod: Zaznacz cały
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class NewClass extends JFrame {
public NewClass() {
setTitle("Simple example");
setSize(300, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
NewClass ex = new NewClass();
ex.setVisible(true);
}
});
}
}
PS. Używam openjdk.
Re: Netbeans nie kompiluje prostej aplikacji SWING
: 24 lip 2011, 19:35
autor: kozio

Mam problem z pierwszym kodem daje run i wywala te błędy.
Kod: Zaznacz cały
Exception in thread "main" java.lang.NoClassDefFoundError: java/Main
Caused by: java.lang.ClassNotFoundException: java.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: java.Main. Program will exit.
Kod: Zaznacz cały
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* NewJFrame.java
*
* Created on 2011-07-24, 19:31:27
*/
package java;
/**
*
* @author daniel
*/
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
// End of variables declaration
}
Żadnego podkreślenia po prostu ten błąd, a w Windows7 działa normalnie.
UU jednak nie nie kompilują się oba.
Re: Netbeans nie kompiluje prostej aplikacji SWING
: 24 lip 2011, 19:52
autor: Semutachi
Możliwe, że błąd występuje w niewłaściwym rozkładzie plików w katalogach. U mnie wygląda on tak
Kod: Zaznacz cały
.
|-- build
| `-- classes
| |-- NewClass$1.class
| `-- NewClass.class
|-- build.xml
|-- nbproject
| |-- build-impl.xml
| |-- genfiles.properties
| |-- private
| | |-- private.properties
| | `-- private.xml
| |-- project.properties
| `-- project.xml
`-- src
`-- NewClass.java
Natomiast u Ciebie ze względu na linię
powinien on wyglądać tak (mi się przynajmniej wydaje, już dłuugi czas nie bawiłem się Javą)
Kod: Zaznacz cały
.
|-- build
| `-- classes
| |-- NewClass$1.class
| `-- NewClass.class
|-- build.xml
|-- nbproject
| |-- build-impl.xml
| |-- genfiles.properties
| |-- private
| | |-- private.properties
| | `-- private.xml
| |-- project.properties
| `-- project.xml
`-- src
|-- java
`-- NewClass.java
Ewentualnie usuń tą linię
Re: Netbeans nie kompiluje prostej aplikacji SWING
: 24 lip 2011, 20:00
autor: kozio
Niestety package java musi być :S
Re: Netbeans nie kompiluje prostej aplikacji SWING
: 24 lip 2011, 20:12
autor: Semutachi
To może podaj po kolei wszystkie kroki jakie wykonujesz (od utworzenia projektu po uruchomienie). I jeszcze jedno, z jakiej wersji NetBeans'a korzystasz?
Re: Netbeans nie kompiluje prostej aplikacji SWING
: 24 lip 2011, 20:30
autor: kozio
Solved, NetBeans 7.0 rozwiązał problem.