Hi
ich habe ein Problem...
undzwar will ich ein Programm schreiben mit dem ma Minecraft Texture Packs installieren kann.
aber ich bekomme immer eine nullpointer exception
code:
exception:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at frame.dialog(frame.java:37)
at frame$TestActionListener.actionPerformed(frame.java:67)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Ich hoffe, dass ihr mir helfen könnt.
ich habe ein Problem...
undzwar will ich ein Programm schreiben mit dem ma Minecraft Texture Packs installieren kann.
aber ich bekomme immer eine nullpointer exception
code:
Java:
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.awt.GridLayout;
import java.awt.event.*;
import java.io.File;
public class frame extends JFrame
{
JButton open = new JButton("Öffnen");
JButton instal = new JButton("Installieren");
JTextField datei = new JTextField("");
JFileChooser fc = new JFileChooser();
File file = fc.getSelectedFile();
public frame()
{
initComponents();
}
public void dialog(){
fc.setFileFilter( new FileFilter()
{
@Override public boolean accept( File f )
{
return f.isDirectory() ||
f.getName().toLowerCase().endsWith( ".zip" );
}
@Override public String getDescription()
{
return "Minecraft Texture Packs";
}
} );
int state = fc.showOpenDialog(null);
if ( state == JFileChooser.APPROVE_OPTION )
{
datei.setText( file.getAbsolutePath() );
}
else
System.out.println( "Auswahl abgebrochen" );
}
private void initComponents()
{
setTitle("Ein reines, unbeflecktes Frame"); // Fenstertitel setzen
open.addActionListener(new TestActionListener()); // EventListener für Schaltfläche hinzufügen
instal.addActionListener(new TestActionListener2());
add(datei);
add(open);
add(instal);// Schaltfläche zum Fenster hinzufügen
pack();
setSize(200,200); // Fenstergröße einstellen
// (notwendig, damit das Fenster geschlossen werden kann)
setVisible(true);
setSize(500, 80);
setLayout(new GridLayout());// Fenster (inkl. Inhalt) sichtbar machen
datei.setEditable(false);
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
class TestActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
dialog();
}
}
class TestActionListener2 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String username = System.getProperty("user.name");
File source = new File(file.getAbsolutePath());
String name = new String(file.getName());
File destination = new File("c:/Users/" + username + "/AppData/Roaming/.minecraft/texturepacks/" + name);
if(!source.renameTo(destination)){
System.err.println("Fehler beim Umbenennen der Datei: " + source.getName());
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new frame();
}
}); // Erzeugt einen neuen Thread, der eine Instanz von TestJFrame erzeugt
}
}
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at frame.dialog(frame.java:37)
at frame$TestActionListener.actionPerformed(frame.java:67)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Ich hoffe, dass ihr mir helfen könnt.