Erro na depois da copilaçao!AJUDEM

1 resposta
M

olha ja tres pessoas tentaram me ajudar…mas ninguem ate agora conseguiu…logico q eu agradeço o q eles fizeram por mim…entaum…esse e um pragrama de visualizar imagens …entaum …ele copila certo…mas ele naum abre a janela q era pra abrir…JFrame…eu queria q vc me ajudasse,se vc ver algum erro nesse codigo me avisem…ou pra melhorar ele e pra eu executar ele certinho…obrigado

esse e o codigo:::

import <a href="http://java.io">java.io</a>.<em>;

import java.awt.</em>;

import java.awt.event.<em>;

import javax.swing.</em>;
public class Janela extends JFrame {

private JLabel label;

private JButton openButton;

private ObjectInputStream input;
public Janela()

{

super (Visualizador de Imagens);
label = new JLabel ();

getContentPane().add(

label,BorderLayout.CENTER);

//openButton = label.getDoTask1Button();
openButton.setText(“Abrir Arquivo”);

openButton.addActionListener(

new ActionListener() {

public void actionPerformed (ActionEvent event)

{

openFile();

}

}

);
addWindowListener (

new WindowAdapter() {

public void windowClosing (WindowEvent event)

{

if(input!=null)

closeFile();
System.exit(0);

}

}

);
pack();

//setSize(500,600);

setVisible(true);

show();

}
private void openFile()

{

JFileChooser fileChooser = new JFileChooser();

fileChooser.setFileSelectionMode(

JFileChooser.FILES_ONLY);

int result = fileChooser.showOpenDialog(this);

if (result == JFileChooser.CANCEL_OPTION)
return;

File fileName = fileChooser.getSelectedFile();

if(fileName == null || fileName.getName().equals(""))
JOptionPane.showMessageDialog(this,“Nome de Arquivo Invalido”,“Arquivo Invalido”,JOptionPane.ERROR_MESSAGE);

else{

try{
input = new ObjectInputStream( new FileInputStream(fileName));

openButton.setEnabled(false);
}

catch (IOException ioException) {

JOptionPane.showMessageDialog(this,Erro ao Abrir o Arquivo,Erro,JOptionPane.ERROR_MESSAGE);

}

}

}
private void closeFile()

{

try{

input.close();

System.exit(0);

}

catch(IOException ioException) {

JOptionPane.showMessageDialog(this,Error closing file,Error,JOptionPane.ERROR_MESSAGE);
System.exit(1);

}

}
public static void main (String args[])

{

Janela application = new Janela();

application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

application.setVisible(true);

}
}

valeu Smile

1 Resposta

P

Esse eh o erro, naum eh:

Exception in thread main java.lang.NullPointerException

at Janela.<init> (Janela.java:21)

at Janela.main(Janela.java:100)

Janela.java:21 -> nesse caso o 21 eh a linha onde o erro esta sendo encontrado…

Tenta inicializar o openButton antes de usar…

Abs

Criado 6 de abril de 2005
Ultima resposta 6 de abr. de 2005
Respostas 1
Participantes 2