Exception in thread “main” java.lang.NullPointerException
este erro aparece quando tento executar estou iniciando em progrmação ai vai o codigo
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
class Janela extends JFrame implements ActionListener{
JLabel L1;
JButton B1,B2,B3;
TextArea TA1;
public static void main(String args[]){
JFrame Janela = new Janela();
WindowListener x = new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
};
Janela.addWindowListener(x);
Janela.show();
}
Janela(){
setTitle("Manipulação de arquivos de texto");
setSize(500,250);
getContentPane().setBackground(new Color(150,150,150));
getContentPane().setLayout(new FlowLayout());
L1.setForeground(Color.black);
B1 = new JButton("Gravar");
B1 = new JButton("Ler");
B1 = new JButton("Limpar");
B1.addActionListener(this);
B2.addActionListener(this);
B3.addActionListener(this);
TA1 = new TextArea(8,60);
getContentPane().add(L1);
getContentPane().add(TA1);
getContentPane().add(B1);
getContentPane().add(B2);
getContentPane().add(B3);
}
public void actionPerformed(ActionEvent e){
String nome_do_arquivo ="c:/arq.txt";
if(e.getSource() == B3)
TA1.setText("");
if(e.getSource() == B1){
try{
String S=TA1.getText();
byte b[] =S.getBytes();
FileOutputStream out = new FileOutputStream(nome_do_arquivo);
out.write(b);
out.close();
}catch(java.io.IOException exc){
System.out.println("Erro ao gravar arquivo");
}
}
if(e.getSource() == B2) {
try{
FileInputStream in = new FileInputStream(nome_do_arquivo);
byte bt[] = new byte[10240];
in.read(bt);
String S= new String(bt);
TA1.setText(S);
in.close();
}catch(java.io.IOException exc){
System.out.println("Erro ao ler arquivo");
}
}
}
}
[color=“green”][size=“9”]*Editado para adicionar o BBCode ;)[/size][/color]