Advertisement
gdog2u

ErrorReport

Mar 20th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.59 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.io.*;
  4. import javax.swing.*;
  5.  
  6.  
  7. public class KBowlChallenge implements ActionListener{
  8.  
  9.    
  10.     JButton startBtn = new JButton("Start");
  11.     JButton answerBtn = new JButton("Answer");
  12.     JButton nextBtn = new JButton("Next");
  13.    
  14.     TextArea questionTA = new TextArea("Welcome to the challenge Mode", 4,30, TextArea.SCROLLBARS_VERTICAL_ONLY);
  15.    
  16.     TextField answerTF = new TextField(10);
  17.     TextField responseTF = new TextField(10);
  18.     TextField rightTF =new TextField("0", 2);
  19.     TextField wrongTF = new TextField("0", 2);
  20.     TextField scoreTF = new TextField(3);
  21.    
  22.     int numRight = 0;
  23.     int numWrong = 0;
  24.     int questionNumber = 0;
  25.    
  26.     static QuestionAnswer[] questAns = new QuestionAnswer[60];
  27.    
  28.     @SuppressWarnings("unused")
  29.     public static void main(String[] args){
  30.         KBowlOpps.fillArrays();
  31.         for(int i=0;i<questAns.length;i++){
  32.             questAns[i] = new QuestionAnswer();
  33.         }
  34.         KBowlChallenge k = new KBowlChallenge();
  35.     }
  36.    
  37.     public KBowlChallenge(){
  38.         JFrame w = new JFrame();
  39.         JPanel p = new JPanel();
  40.        
  41.         JLabel scoreLbl= new JLabel("Score: ");
  42.         JLabel rightLbl = new JLabel("Correct: ");
  43.         JLabel wrongLbl = new JLabel("Wrong: ");
  44.        
  45.         w.setSize(300,350);
  46.         w.setTitle("Challenge Mode");
  47.         w.setLocationRelativeTo(null);
  48.         w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  49.         w.setVisible(true);
  50.        
  51.         p.setLayout(new FlowLayout());
  52.         p.add(startBtn);
  53.             startBtn.addActionListener(this);
  54.         //p.add(Box.createHorizontalStrut(80));
  55.         //break
  56.         p.add(questionTA);
  57.             questionTA.setEditable(false);
  58.         //p.add(Box.createHorizontalStrut(80));
  59.         //break
  60.         p.add(answerTF);
  61.         //p.add(Box.createHorizontalStrut(90));
  62.         //break
  63.         p.add(answerBtn);
  64.             answerBtn.addActionListener(this);
  65.         p.add(Box.createHorizontalStrut(60));
  66.         p.add(responseTF);
  67.         p.add(nextBtn);
  68.             nextBtn.addActionListener(this);
  69.         p.add(Box.createHorizontalStrut(50));
  70.         //break
  71.         p.add(scoreLbl);
  72.         p.add(scoreTF);
  73.         p.add(rightLbl);
  74.         p.add(rightTF);
  75.         p.add(wrongLbl);
  76.         p.add(wrongTF);
  77.         w.add(p);
  78.        
  79.     }
  80.  
  81.    
  82.     public void actionPerformed(ActionEvent e){
  83.        
  84.         if(e.getSource() == this.startBtn){
  85.             questionTA.setText("");
  86.             questionTA.append(questAns[questionNumber].getQuestion());
  87.             System.out.print("Test");
  88.             questAns = KBowlOpps.getChallengeQuestions();
  89.         }
  90.         if(e.getSource() == this.nextBtn){
  91.             questionNumber++;
  92.             questionTA.setText("");
  93.             answerTF.setText("");
  94.             questionTA.append(questAns[questionNumber].getQuestion());
  95.         }
  96.         if(e.getSource() == this.answerBtn){
  97.             String answer = questAns[questionNumber].getAnswer();
  98.             String input = answerTF.getText();
  99.             System.out.println(answer);
  100.             System.out.println(answerTF.getText());
  101.             if(answer == input){
  102.                 responseTF.setText("Correct!");
  103.                 numRight++;
  104.             }else{
  105.                 responseTF.setText("Incorrect!");
  106.                 numWrong++;
  107.             }
  108.             rightTF.setText(numRight+"");
  109.             wrongTF.setText(numWrong+"");
  110.         }
  111.            
  112.        
  113.     }
  114.    
  115. }
  116.  
  117. ============================================================================================
  118. Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: null string
  119.     at sun.awt.windows.WTextAreaPeer.insertText(Native Method)
  120.     at sun.awt.windows.WTextAreaPeer.insert(Unknown Source)
  121.     at java.awt.TextArea.insertText(Unknown Source)
  122.     at java.awt.TextArea.appendText(Unknown Source)
  123.     at java.awt.TextArea.append(Unknown Source)
  124.     at KBowlChallenge.actionPerformed(KBowlChallenge.java:86)
  125.     at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
  126.     at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
  127.     at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
  128.     at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
  129.     at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
  130.     at java.awt.Component.processMouseEvent(Unknown Source)
  131.     at javax.swing.JComponent.processMouseEvent(Unknown Source)
  132.     at java.awt.Component.processEvent(Unknown Source)
  133.     at java.awt.Container.processEvent(Unknown Source)
  134.     at java.awt.Component.dispatchEventImpl(Unknown Source)
  135.     at java.awt.Container.dispatchEventImpl(Unknown Source)
  136.     at java.awt.Component.dispatchEvent(Unknown Source)
  137.     at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
  138.     at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
  139.     at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
  140.     at java.awt.Container.dispatchEventImpl(Unknown Source)
  141.     at java.awt.Window.dispatchEventImpl(Unknown Source)
  142.     at java.awt.Component.dispatchEvent(Unknown Source)
  143.     at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
  144.     at java.awt.EventQueue.access$200(Unknown Source)
  145.     at java.awt.EventQueue$3.run(Unknown Source)
  146.     at java.awt.EventQueue$3.run(Unknown Source)
  147.     at java.security.AccessController.doPrivileged(Native Method)
  148.     at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
  149.     at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
  150.     at java.awt.EventQueue$4.run(Unknown Source)
  151.     at java.awt.EventQueue$4.run(Unknown Source)
  152.     at java.security.AccessController.doPrivileged(Native Method)
  153.     at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
  154.     at java.awt.EventQueue.dispatchEvent(Unknown Source)
  155.     at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
  156.     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
  157.     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
  158.     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  159.     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  160.     at java.awt.EventDispatchThread.run(Unknown Source)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement