Exception in thread AWT-EventQueue-0 java.lang.NullPointer
Estou recebendo esse erro e não sei como resolver!
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.lang.StringBuilder.<init>(StringBuilder.java:112)
at Cadastro.Lista$BuTTonPartida.actionPerformed(Lista.java:192)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.lang.StringBuilder.<init>(StringBuilder.java:112)
at Cadastro.Lista$BuTTonPartida.actionPerformed(Lista.java:192)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
public Lista() {
setLayout(new BorderLayout());
JPanel painel = new JPanel();
painel.setLayout( new FlowLayout() );
setSize(520, 280);
setVisible(true);
add(painel);
pbotao.setLayout(new FlowLayout());
add(pbotao,BorderLayout.CENTER);
iniciar = new JButton( "Iniciar" );
sair = new JButton ("Sair");
reiniciar = new JButton ("Jogo de Adivinhar");
//sair.addActionListener();// create copy button
//iniciar.addActionListener();
pbotao.add(iniciar);
pbotao.add(sair);
pbotao.add(reiniciar);
iniciar.addActionListener(inicio);
sair.addActionListener(saida);
reiniciar.addActionListener(reinicio);
}
Thread T;
public void loop(){
T = new Thread(){
@Override
public void run(){
try{
adivinha();
}catch (Exception e){
System.exit(0);
}
}
};
T.start();
}
public void finalizar(){
Thread fim = new Thread(){
@Override
public void run(){
try{
System.exit(0);
}catch (Exception e){
}
}
};
fim.start();
}
public void adivinha(){
Scanner input = new Scanner(System.in);
int opcao = 0;
boolean x = true;
JOptionPane.showMessageDialog(null, "A partir de agora vai começar o jogo da adivinha!"+"\\nAgora olhe para a parte inferior e central do seu video para começar! ");
String[] strings1 = { "VADJO", "BIG MAC", "LEONAM", "PAIOL" };
System.out.println(">>> TENTE ADIVINHAR ALGUNS NOMES <<<");
System.out.println("VOCÊ TERÁ ALGUMAS CHANCES...");
System.out.println("✔ QUANDO QUISER PARAR DIGITE A LETRA 'z'");
do{
System.out.println("DIGITE A PRIMEIRA LETRA DE UM DOS 4 NOMES QUE TEMOS!");
String letra = input.next();
switch(letra){
case "l":
if(letra.equals("l")){
for ( String string : strings1 ){
if ( string.startsWith( "L", 0 ) )
System.out.printf( "\\"%s\\" começa com \\"L\\"\\n", string );
}
System.out.println("PARABÉNS, VOCÊ ACERTOU!");
break;
}
case "v":
if(letra.equals("v")){
for ( String string : strings1 ){
if ( string.startsWith( "V", 0 ) )
System.out.printf( "\\"%s\\" começa com \\"V\\"\\n", string );
}
System.out.println("PARABÉNS, VOCÊ ACERTOU!");
break;
}
case "b":
if(letra.equals("b")){
for ( String string : strings1 ){
if ( string.startsWith( "B", 0 ) )
System.out.printf( "\\"%s\\" começa com \\"L\\"\\n", string );
}
System.out.println("PARABÉNS, VOCÊ ACERTOU!");
break;
}
case "p":
if(letra.equals("p")){
for ( String string : strings1 ){
if ( string.startsWith( "P", 0 ) )
System.out.printf( "\\"%s\\" começa com \\"L\\"\\n", string );
}
System.out.println("PARABÉNS, VOCÊ ACERTOU!");
break;
}
case "z":
if(letra.equals("z"))
x = true;
System.exit(0);
default:
System.out.println("NÃO TEM PALAVRA QUE COMEÇA COM ESSA LETRA!");
break;
} // end main
}
while( x =! false);
// end class StringStartEnd
}
private class BuTTonReiniciar implements ActionListener
{
public void actionPerformed(ActionEvent ae) {
loop();
}
}
private class BuTTonPartida implements ActionListener
{
public void actionPerformed( ActionEvent event )
{
String frase;
frase = JOptionPane.showInputDialog("Digite alguma frase, iremos mostrar o tamanho dela + lida de trás pra frente!");
StringBuilder buffer = new StringBuilder(frase);
JOptionPane.showMessageDialog(null,"Tamanho da frase: "+frase.length());
JOptionPane.showMessageDialog(null,"Frase de trás pra frente: "+buffer.reverse());
Bruno
Curtidas 0
Respostas
Marcio Souza
19/06/2017
Segundo a exceção está rolando um java.lang.NullPointerException. Significa que você está acessando algum objeto que está nulo. Precisa identificar o porque ele está nulo. A parte do código que lança a exceção é essa:
Ou seja, na Cadastro tem um método chamado Lista o qual deve ter uma classe interna chamada BuTTonPartida. A exceção está estourando nessa classe interna. Mais especificamente na linha 192.
at Cadastro.Lista$BuTTonPartida.actionPerformed(Lista.java:192)
Ou seja, na Cadastro tem um método chamado Lista o qual deve ter uma classe interna chamada BuTTonPartida. A exceção está estourando nessa classe interna. Mais especificamente na linha 192.
GOSTEI 0
Bruno
19/06/2017
nesta linha tem isso
o que eu faço ?
StringBuilder buffer = new StringBuilder(frase);
o que eu faço ?
GOSTEI 0