Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 25 of 25

Thread: Counter behaving oddly, skipping large blocks of code& error message

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Counter behaving oddly, skipping large blocks of code& error message

    buttonPressA();
        buttonPressB();
        buttonPressC();
        buttonPressD();
        totalquestions=-1;//Don't ask why, it just works.
        answer=solutions[0];//Counter iterates once inexpicably, this is a countermeasure
        txta_display.setText("Press an answer button to begin");
     
      if (totalquestions==0){  
        txta_display.setText("What is the slope of a line containing (2,4) and (4,8)?\n A. 2\n B. 3\n C. 13\n D. 1");
        if (answer==solutions[1]){
            score=score+1;
            System.out.println("answer:"+answer);
        System.out.println("solution:"+ java.util.Arrays.toString(solutions));
        System.out.println("question"+totalquestions);
    }
     
     
     
        if (totalquestions==1){
             txta_display.setText("What is the slope of the line containing (3,9) and (2,6)?\n A. 4\n B. 3\n C. 6\n D. 1");
             if (answer==solutions[2]){
                 score=score+1; 
             }
        }
        else if(totalquestions==2){
            txta_display.setText("What does a statement like x=4 mean?\n A. nothing\n B. straight line through a y value\n C. No line exists.\nD. The line passes thrrough an x value");
            if (answer==solutions[3]) {
                  score=score+1;
            }
             System.out.println("answer:"+answer);
             System.out.println("solution:"+ java.util.Arrays.toString(solutions));
             System.out.println("1 Score: "+score);
             System.out.println("question"+totalquestions); 
        }
        if (totalquestions==3){
           txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[4]){
                score=score+1;
                System.out.println("answer:"+answer);
                System.out.println("solution:"+ java.util.Arrays.toString(solutions));
            }
            System.out.println("2 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions==4){
        txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[5]){
                score=score+1;
                 System.out.println("answer:"+answer);
                 System.out.println("solution:"+ java.util.Arrays.toString(solutions));
         }
            System.out.println("3 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions>4){
            txta_display.setText("You have finished! Your score is "+score+" out of 5");
        }
      }

    When I run this part of the program, it either stops after one iteration, or after I moved my answer button methods, I received the following wall of text as an error message:

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at slopelessonculminating.SlopeLessonCulminatingView. buttonPressA(SlopeLessonCulminatingView.java:46)
    at slopelessonculminating.SlopeLessonCulminatingView. btn_quizActionPerformed(SlopeLessonCulminatingView .java:410)
    at slopelessonculminating.SlopeLessonCulminatingView. access$1000(SlopeLessonCulminatingView.java:22)
    at slopelessonculminating.SlopeLessonCulminatingView$ 6.actionPerformed(SlopeLessonCulminatingView.java: 225)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.jav a:6505)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3321)
    at java.awt.Component.processEvent(Component.java:627 0)
    at java.awt.Container.processEvent(Container.java:222 9)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4861)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2719 )
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:723)
    at java.awt.EventQueue.access$200(EventQueue.java:103 )
    at java.awt.EventQueue$3.run(EventQueue.java:682)
    at java.awt.EventQueue$3.run(EventQueue.java:680)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:696)
    at java.awt.EventQueue$4.run(EventQueue.java:694)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 693)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:244)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:147)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:139)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:97)
    Any ideas?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at slopelessonculminating.SlopeLessonCulminatingView. buttonPressA(SlopeLessonCulminatingView.java:46)
    There is a variable with a null value when the code at line 46 executes which causes this exception.
    Look at line 46, find the variable with the null value and then backtrack in the code to see why that variable does not have a valid value. If you can not tell which variable is null, add a println after line 45 that prints out the values of all the variables used on line 46.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    Ok, partially fixed that. It doesn't return the error message.

    However, it stays on the first display, rather than changing what's in the text area. The counter for totalquestions has a sudden jump I've accounted for, but behaves normally. What's happening that I keep missing?

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    I'm not sure that I can help based on what you've posted so far. You should use your println statements to help debug and isolate your error. Then if still stuck, post the new code and any new information about your bug here.

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    I think I've found something that might help. My code now looks like
    txta_display.setText("Press an answer button to begin");
     if (totalquestions==4){
     
        txta_display.setText("What is the slope of a line containing (2,4) and (4,8)?\n A. 2\n B. 3\n C. 13\n D. 1");
        if (answer==solutions[1]){
            score=score+1;
    }
        System.out.println("answer:"+answer);
        System.out.println("solution:"+ java.util.Arrays.toString(solutions));
        System.out.println("question"+totalquestions);
     
        if (totalquestions==5){
             txta_display.setText("What is the slope of the line containing (3,9) and (2,6)?\n A. 4\n B. 3\n C. 6\n D. 1");
             if (answer==solutions[2]){
                 score=score+1; 
             System.out.println("answer:"+answer);
             System.out.println("solution:"+ java.util.Arrays.toString(solutions));
             System.out.println("1 Score: "+score);
             System.out.println("question"+totalquestions); 
             }
        }
        else if(totalquestions==6){
            txta_display.setText("What does a statement like x=4 mean?\n A. nothing\n B. straight line through a y value\n C. No line exists.\nD. The line passes thrrough an x value");
            if (answer==solutions[3]) {
                  score=score+1;
            }
             System.out.println("answer:"+answer);
             System.out.println("solution:"+ java.util.Arrays.toString(solutions));
             System.out.println("1 Score: "+score);
             System.out.println("question"+totalquestions); 
        }
        if (totalquestions==7){
           txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[4]){
                score=score+1;
                System.out.println("answer:"+answer);
                System.out.println("solution:"+ java.util.Arrays.toString(solutions));
            }
            System.out.println("2 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions==8){
        txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[5]){
                score=score+1;
                 System.out.println("answer:"+answer);
                 System.out.println("solution:"+ java.util.Arrays.toString(solutions));
         }
            System.out.println("3 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions>8){
            txta_display.setText("You have finished! Your score is "+score+" out of 5");
        }
      }

    Now when I run it, it displays the first question, however, if I answer it, it jumps back to the opening statement. Ideas?

  6. #6
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    What user interface are you using? Is this a Swing or AWT GUI program? Where is input obtained from the user?

  7. #7
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    AWT GUI. Input comes from buttons that when pressed, trigger a method which returns a numerical value that represents their answer. It also is the one responsible for cycling the questions.

    Should I post one of them? The code is pretty much identical.

  8. #8
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    Um, bump?

  9. #9
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    I think that you should post more. Consider creating and posting an SSCCE where you condense your code into the smallest bit that still compiles and runs, has no outside dependencies (such as need to link to a database or images), has no extra code that's not relevant to your problem, but still demonstrates your problem.

  10. #10
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    I'm having a little trouble setting the SSCE up... Sorry.

    The offending code is as shown, I just copypasted it into the answer buttons, but the only other part of the code I think is missing are the answering methods themselves.

    answer=A;
     
            if(A.equals(solutions)){           
                totalquestions=totalquestions+1;                  
        }
            else {
                totalquestions=totalquestions+1;
            }    
            System.out.println(""+totalquestions);
            System.out.println("3 Score: "+score);
            return answer;  
    }
     
    public Integer buttonPressB(){
     
    answer=B;
     
        if(B.equals(solutions)){
             totalquestions=totalquestions+1;  
        }
        else {
            totalquestions=totalquestions+1;
        }
        System.out.println("3 Score: "+score);
        System.out.println(""+totalquestions);
        return answer;
    }
     
    public Integer buttonPressC(){
     
    answer=C;
     
        if (C.equals(solutions)){
            totalquestions=totalquestions+1;
        }
        else{
            totalquestions=totalquestions+1;
        }
        System.out.println("3 Score: "+score);
        System.out.println(""+totalquestions);
        return answer;
    }
     
    public Integer buttonPressD(){
     
    answer=D;
     
        if(D.equals(solutions)){
           totalquestions=totalquestions+1;  
        }
        else{
            totalquestions=totalquestions+1;
        }
        System.out.println(""+totalquestions);
        return answer;
    Everything else works fine, the code I've shared is all that's relevant to my problem, sorry I can't really be of more help.

    When I run it now, it goes to the first question fine, but after I press a button to answer, it jumps back to the start prompt, the score counter increments regardless of whether or not it was correct, and I get the following output:

    0
    3 Score: 0
    3 Score: 0
    1
    3 Score: 0
    2
    3
    4
    3 Score: 0
    answer:1
    solution:[0, 1, 2, 4, 3, 4]
    question4
    5
    3 Score: 1

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    the code I've shared is all that's relevant to my problem,
    It makes it hard to compile, execute and test the code without a SSCCE.

    Make a SSCCE driver with hardcoded values that executes the above code that has the error. It needs to define all the variables used in the above code and give them values that will show the problem.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    Alright, how should I attach it?

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    Post the SSCCE in the forum just like the code you posted earlier in post#10. Wrapped in code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    *
     * SSCCEOfProblemView.java
     */
     
    package sscceofproblem;
     
    import org.jdesktop.application.Action;
    import org.jdesktop.application.ResourceMap;
    import org.jdesktop.application.SingleFrameApplication;
    import org.jdesktop.application.FrameView;
    import org.jdesktop.application.TaskMonitor;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Timer;
    import javax.swing.Icon;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
     
    /**
     * The application's main frame.
     */
    public class SSCCEOfProblemView extends FrameView {
    Integer[] solutions={0,1,2,4,3,4};
    Integer answer;
    Integer totalquestions=-1;;
    int score, correct;
    Integer step=1;
    Integer A=1;
    Integer B=2;
    Integer C=3;
    Integer D=4;
        public Integer buttonPressA(){
     
    answer=A;
     
            if(A.equals(solutions)){           
                totalquestions=totalquestions+1;                  
        }
            else {
                totalquestions=totalquestions+1;
            }    
            System.out.println(""+totalquestions);
            System.out.println("3 Score: "+score);
            return answer;  
    }
     
    public Integer buttonPressB(){
     
    answer=B;
     
        if(B.equals(solutions)){
             totalquestions=totalquestions+1;  
        }
        else {
            totalquestions=totalquestions+1;
        }
        System.out.println("3 Score: "+score);
        System.out.println(""+totalquestions);
        return answer;
    }
     
    public Integer buttonPressC(){
     
    answer=C;
     
        if (C.equals(solutions)){
            totalquestions=totalquestions+1;
        }
        else{
            totalquestions=totalquestions+1;
        }
        System.out.println("3 Score: "+score);
        System.out.println(""+totalquestions);
        return answer;
    }
     
    public Integer buttonPressD(){
     
    answer=D;
     
        if(D.equals(solutions)){
           totalquestions=totalquestions+1;  
        }
        else{
            totalquestions=totalquestions+1;
        }
        System.out.println(""+totalquestions);
        return answer;
    }
        public SSCCEOfProblemView(SingleFrameApplication app) {
            super(app);
     
            initComponents();
     
            // status bar initialization - message timeout, idle icon and busy animation, etc
            ResourceMap resourceMap = getResourceMap();
            int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
            messageTimer = new Timer(messageTimeout, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    statusMessageLabel.setText("");
                }
            });
            messageTimer.setRepeats(false);
            int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
            for (int i = 0; i < busyIcons.length; i++) {
                busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
            }
            busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                    statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
                }
            });
            idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
            statusAnimationLabel.setIcon(idleIcon);
            progressBar.setVisible(false);
     
            // connecting action tasks to status bar via TaskMonitor
            TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
            taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
                public void propertyChange(java.beans.PropertyChangeEvent evt) {
                    String propertyName = evt.getPropertyName();
                    if ("started".equals(propertyName)) {
                        if (!busyIconTimer.isRunning()) {
                            statusAnimationLabel.setIcon(busyIcons[0]);
                            busyIconIndex = 0;
                            busyIconTimer.start();
                        }
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(true);
                    } else if ("done".equals(propertyName)) {
                        busyIconTimer.stop();
                        statusAnimationLabel.setIcon(idleIcon);
                        progressBar.setVisible(false);
                        progressBar.setValue(0);
                    } else if ("message".equals(propertyName)) {
                        String text = (String)(evt.getNewValue());
                        statusMessageLabel.setText((text == null) ? "" : text);
                        messageTimer.restart();
                    } else if ("progress".equals(propertyName)) {
                        int value = (Integer)(evt.getNewValue());
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(false);
                        progressBar.setValue(value);
                    }
                }
            });
        }
     
        @Action
        public void showAboutBox() {
            if (aboutBox == null) {
                JFrame mainFrame = SSCCEOfProblemApp.getApplication().getMainFrame();
                aboutBox = new SSCCEOfProblemAboutBox(mainFrame);
                aboutBox.setLocationRelativeTo(mainFrame);
            }
            SSCCEOfProblemApp.getApplication().show(aboutBox);
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            mainPanel = new javax.swing.JPanel();
            btn_A = new javax.swing.JButton();
            btn_B = new javax.swing.JButton();
            btn_C = new javax.swing.JButton();
            btn_D = new javax.swing.JButton();
            jScrollPane1 = new javax.swing.JScrollPane();
            txta_display = new javax.swing.JTextArea();
            btn_quiz = new javax.swing.JButton();
            btn_quiz1 = new javax.swing.JButton();
            menuBar = new javax.swing.JMenuBar();
            javax.swing.JMenu fileMenu = new javax.swing.JMenu();
            javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
            javax.swing.JMenu helpMenu = new javax.swing.JMenu();
            javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
            statusPanel = new javax.swing.JPanel();
            javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
            statusMessageLabel = new javax.swing.JLabel();
            statusAnimationLabel = new javax.swing.JLabel();
            progressBar = new javax.swing.JProgressBar();
     
            mainPanel.setName("mainPanel"); // NOI18N
     
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sscceofproblem.SSCCEOfProblemApp.class).getContext().getResourceMap(SSCCEOfProblemView.class);
            btn_A.setText(resourceMap.getString("btn_A.text")); // NOI18N
            btn_A.setName("btn_A"); // NOI18N
            btn_A.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btn_AActionPerformed(evt);
                }
            });
     
            btn_B.setText(resourceMap.getString("btn_B.text")); // NOI18N
            btn_B.setName("btn_B"); // NOI18N
            btn_B.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btn_BActionPerformed(evt);
                }
            });
     
            btn_C.setText(resourceMap.getString("btn_C.text")); // NOI18N
            btn_C.setName("btn_C"); // NOI18N
            btn_C.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btn_CActionPerformed(evt);
                }
            });
     
            btn_D.setText(resourceMap.getString("btn_D.text")); // NOI18N
            btn_D.setName("btn_D"); // NOI18N
            btn_D.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btn_DActionPerformed(evt);
                }
            });
     
            jScrollPane1.setName("jScrollPane1"); // NOI18N
     
            txta_display.setColumns(20);
            txta_display.setLineWrap(true);
            txta_display.setRows(5);
            txta_display.setWrapStyleWord(true);
            txta_display.setName("txta_display"); // NOI18N
            jScrollPane1.setViewportView(txta_display);
     
            btn_quiz.setText(resourceMap.getString("btn_quiz.text")); // NOI18N
            btn_quiz.setName("btn_quiz"); // NOI18N
     
            btn_quiz1.setText(resourceMap.getString("btn_quiz1.text")); // NOI18N
            btn_quiz1.setName("btn_quiz1"); // NOI18N
            btn_quiz1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btn_quiz1ActionPerformed(evt);
                }
            });
     
            javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
            mainPanel.setLayout(mainPanelLayout);
            mainPanelLayout.setHorizontalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addGap(153, 153, 153)
                    .addComponent(btn_A)
                    .addGap(18, 18, 18)
                    .addComponent(btn_B)
                    .addGap(18, 18, 18)
                    .addComponent(btn_C)
                    .addGap(18, 18, 18)
                    .addComponent(btn_D)
                    .addContainerGap(37, Short.MAX_VALUE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                    .addGap(20, 20, 20)
                    .addComponent(btn_quiz1)
                    .addGap(18, 18, 18)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE)
                    .addGap(20, 20, 20))
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(0, 159, Short.MAX_VALUE)
                        .addComponent(btn_quiz)
                        .addGap(0, 160, Short.MAX_VALUE)))
            );
            mainPanelLayout.setVerticalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addContainerGap(12, Short.MAX_VALUE)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btn_A)
                                .addComponent(btn_B)
                                .addComponent(btn_C)
                                .addComponent(btn_D))
                            .addGap(18, 18, 18))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                            .addComponent(btn_quiz1)
                            .addGap(93, 93, 93))))
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(0, 115, Short.MAX_VALUE)
                        .addComponent(btn_quiz)
                        .addGap(0, 116, Short.MAX_VALUE)))
            );
     
            menuBar.setName("menuBar"); // NOI18N
     
            fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
            fileMenu.setName("fileMenu"); // NOI18N
     
            javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(sscceofproblem.SSCCEOfProblemApp.class).getContext().getActionMap(SSCCEOfProblemView.class, this);
            exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
            exitMenuItem.setName("exitMenuItem"); // NOI18N
            fileMenu.add(exitMenuItem);
     
            menuBar.add(fileMenu);
     
            helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
            helpMenu.setName("helpMenu"); // NOI18N
     
            aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
            aboutMenuItem.setName("aboutMenuItem"); // NOI18N
            helpMenu.add(aboutMenuItem);
     
            menuBar.add(helpMenu);
     
            statusPanel.setName("statusPanel"); // NOI18N
     
            statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
     
            statusMessageLabel.setName("statusMessageLabel"); // NOI18N
     
            statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
            statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
     
            progressBar.setName("progressBar"); // NOI18N
     
            javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
            statusPanel.setLayout(statusPanelLayout);
            statusPanelLayout.setHorizontalGroup(
                statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(statusMessageLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 230, Short.MAX_VALUE)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(statusAnimationLabel)
                    .addContainerGap())
            );
            statusPanelLayout.setVerticalGroup(
                statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(statusPanelLayout.createSequentialGroup()
                    .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(statusMessageLabel)
                        .addComponent(statusAnimationLabel)
                        .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(3, 3, 3))
            );
     
            setComponent(mainPanel);
            setMenuBar(menuBar);
            setStatusBar(statusPanel);
        }// </editor-fold>
     
    private void btn_AActionPerformed(java.awt.event.ActionEvent evt) {
    //This begins the answer buttons
    buttonPressA();
     
    txta_display.setText("Press an answer button to begin");
     if (totalquestions==4){
     
        txta_display.setText("What is the slope of a line containing (2,4) and (4,8)?\n A. 2\n B. 3\n C. 13\n D. 1");
        if (answer==solutions[1]){
            score=score+1;
    }
        System.out.println("answer:"+answer);
        System.out.println("solution:"+ java.util.Arrays.toString(solutions));
        System.out.println("question"+totalquestions);
     
        if (totalquestions==5){
             txta_display.setText("What is the slope of the line containing (3,9) and (2,6)?\n A. 4\n B. 3\n C. 6\n D. 1");
             if (answer==solutions[2]){
                 score=score+1; 
             System.out.println("answer:"+answer);
             System.out.println("solution:"+ java.util.Arrays.toString(solutions));
             System.out.println("1 Score: "+score);
             System.out.println("question"+totalquestions); 
             }
        }
        else if(totalquestions==6){
            txta_display.setText("What does a statement like x=4 mean?\n A. nothing\n B. straight line through a y value\n C. No line exists.\nD. The line passes thrrough an x value");
            if (answer==solutions[3]) {
                  score=score+1;
            }
             System.out.println("answer:"+answer);
             System.out.println("solution:"+ java.util.Arrays.toString(solutions));
             System.out.println("1 Score: "+score);
             System.out.println("question"+totalquestions); 
        }
        if (totalquestions==7){
           txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[4]){
                score=score+1;
                System.out.println("answer:"+answer);
                System.out.println("solution:"+ java.util.Arrays.toString(solutions));
            }
            System.out.println("2 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions==8){
        txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[5]){
                score=score+1;
                 System.out.println("answer:"+answer);
                 System.out.println("solution:"+ java.util.Arrays.toString(solutions));
         }
            System.out.println("3 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions>8){
            txta_display.setText("You have finished! Your score is "+score+" out of 5");
        }
      }
     
    }
     
    private void btn_BActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
       buttonPressB();
       txta_display.setText("Press an answer button to begin");
     
        if (totalquestions==4){
     
        txta_display.setText("What is the slope of a line containing (2,4) and (4,8)?\n A. 2\n B. 3\n C. 13\n D. 1");
        if (answer==solutions[1]){
            score=score+1;
    }
        System.out.println("answer:"+answer);
        System.out.println("solution:"+ java.util.Arrays.toString(solutions));
        System.out.println("question"+totalquestions);
     
     
        if (totalquestions==5){
             txta_display.setText("What is the slope of the line containing (3,9) and (2,6)?\n A. 4\n B. 3\n C. 6\n D. 1");
             if (answer==solutions[2]){
                 score=score+1; 
                  System.out.println("answer:"+answer);
             System.out.println("solution:"+ java.util.Arrays.toString(solutions));
             System.out.println("1 Score: "+score);
             System.out.println("question"+totalquestions); 
             }
        }
        else if(totalquestions==6){
            txta_display.setText("What does a statement like x=4 mean?\n A. nothing\n B. straight line through a y value\n C. No line exists.\nD. The line passes thrrough an x value");
            if (answer==solutions[3]) {
                  score=score+1;
            }
             System.out.println("answer:"+answer);
             System.out.println("solution:"+ java.util.Arrays.toString(solutions));
             System.out.println("1 Score: "+score);
             System.out.println("question"+totalquestions); 
        }
        if (totalquestions==7){
           txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[4]){
                score=score+1;
                System.out.println("answer:"+answer);
                System.out.println("solution:"+ java.util.Arrays.toString(solutions));
            }
            System.out.println("2 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions==8){
        txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[5]){
                score=score+1;
                 System.out.println("answer:"+answer);
                 System.out.println("solution:"+ java.util.Arrays.toString(solutions));
         }
            System.out.println("3 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions>8){
            txta_display.setText("You have finished! Your score is "+score+" out of 5");
        }
      }
     
    }
     
    private void btn_CActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
       buttonPressC();
       txta_display.setText("Press an answer button to begin");
      if (totalquestions==4){      
        txta_display.setText("What is the slope of a line containing (2,4) and (4,8)?\n A. 2\n B. 3\n C. 13\n D. 1");
        if (answer==solutions[1]){
            score=score+1;  
            System.out.println("answer:"+answer);
            System.out.println("solution:"+ java.util.Arrays.toString(solutions));
            System.out.println("question"+totalquestions);
    }
      else if (totalquestions==5){
             txta_display.setText("What is the slope of the line containing (3,9) and (2,6)?\n A. 4\n B. 3\n C. 6\n D. 1");
             if (answer==solutions[2]){
                 score=score+1; 
                  System.out.println("answer:"+answer);
             System.out.println("solution:"+ java.util.Arrays.toString(solutions));
             System.out.println("1 Score: "+score);
             System.out.println("question"+totalquestions); 
             }
        }
        else if(totalquestions==6){
            txta_display.setText("What does a statement like x=4 mean?\n A. nothing\n B. straight line through a y value\n C. No line exists.\nD. The line passes thrrough an x value");
            if (answer==solutions[3]) {
                  score=score+1;
            }
             System.out.println("answer:"+answer);
             System.out.println("solution:"+ java.util.Arrays.toString(solutions));
             System.out.println("1 Score: "+score);
             System.out.println("question"+totalquestions); 
        }
        if (totalquestions==7){
           txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[4]){
                score=score+1;
                System.out.println("answer:"+answer);
                System.out.println("solution:"+ java.util.Arrays.toString(solutions));
            }
            System.out.println("2 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions==8){
        txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[5]){
                score=score+1;
                 System.out.println("answer:"+answer);
                 System.out.println("solution:"+ java.util.Arrays.toString(solutions));
         }
            System.out.println("3 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions>8){
            txta_display.setText("You have finished! Your score is "+score+" out of 5");
        }
     
    }                                        
    }
     
    private void btn_DActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
        buttonPressD();
        txta_display.setText("Press an answer button to begin");
        if (totalquestions==4){
     
        txta_display.setText("What is the slope of a line containing (2,4) and (4,8)?\n A. 2\n B. 3\n C. 13\n D. 1");
        if (answer==solutions[1]){
             System.out.println("answer:"+answer);
             System.out.println("solution:"+ java.util.Arrays.toString(solutions));
             System.out.println("1 Score: "+score);
             System.out.println("question"+totalquestions); 
            score=score+1;
    }
        System.out.println("answer:"+answer);
        System.out.println("solution:"+ java.util.Arrays.toString(solutions));
        System.out.println("question"+totalquestions);
     
        if (totalquestions==5){
             txta_display.setText("What is the slope of the line containing (3,9) and (2,6)?\n A. 4\n B. 3\n C. 6\n D. 1");
             if (answer==solutions[2]){
                 score=score+1; 
             System.out.println("answer:"+answer);
             System.out.println("solution:"+ java.util.Arrays.toString(solutions));
             System.out.println("1 Score: "+score);
             System.out.println("question"+totalquestions); 
             }
        }
        else if(totalquestions==6){
            txta_display.setText("What does a statement like x=4 mean?\n A. nothing\n B. straight line through a y value\n C. No line exists.\nD. The line passes thrrough an x value");
            if (answer==solutions[3]) {
                  score=score+1;
            }
             System.out.println("answer:"+answer);
             System.out.println("solution:"+ java.util.Arrays.toString(solutions));
             System.out.println("1 Score: "+score);
             System.out.println("question"+totalquestions); 
        }
        if (totalquestions==7){
           txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[4]){
                score=score+1;
                System.out.println("answer:"+answer);
                System.out.println("solution:"+ java.util.Arrays.toString(solutions));
            }
            System.out.println("2 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions==8){
        txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[5]){
                score=score+1;
                 System.out.println("answer:"+answer);
                 System.out.println("solution:"+ java.util.Arrays.toString(solutions));
         }
            System.out.println("3 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions>8){
            txta_display.setText("You have finished! Your score is "+score+" out of 5");
        }
      }
     
    }
     
    private void btn_quiz1ActionPerformed(java.awt.event.ActionEvent evt) {
    // The quiz is started by pressing this.
        buttonPressA();
        buttonPressB();
        buttonPressC();
        buttonPressD();
        answer=solutions[0];//Counter iterates once inexpicably, this is a countermeasure
        txta_display.setText("Press an answer button to begin");
     
      if (totalquestions==4){  
        txta_display.setText("What is the slope of a line containing (2,4) and (4,8)?\n A. 2\n B. 3\n C. 13\n D. 1");
        if (answer==solutions[1]){
            score=score+1;
            System.out.println("answer:"+answer);
            System.out.println("solution:"+ java.util.Arrays.toString(solutions));
            System.out.println("question"+totalquestions);
    } 
        else if (totalquestions==5){
             txta_display.setText("What is the slope of the line containing (3,9) and (2,6)?\n A. 4\n B. 3\n C. 6\n D. 1");
             if (answer==solutions[2]){
                 score=score+1; 
             }
        }
        else if(totalquestions==6){
            txta_display.setText("What does a statement like x=4 mean?\n A. nothing\n B. straight line through a y value\n C. No line exists.\nD. The line passes thrrough an x value");
            if (answer==solutions[3]) {
                  score=score+1;
            }
             System.out.println("answer:"+answer);
             System.out.println("solution:"+ java.util.Arrays.toString(solutions));
             System.out.println("1 Score: "+score);
             System.out.println("question"+totalquestions); 
        }
        if (totalquestions==7){
           txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[4]){
                score=score+1;
                System.out.println("answer:"+answer);
                System.out.println("solution:"+ java.util.Arrays.toString(solutions));
            }
            System.out.println("2 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions==8){
        txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[5]){
                score=score+1;
                 System.out.println("answer:"+answer);
                 System.out.println("solution:"+ java.util.Arrays.toString(solutions));
         }
            System.out.println("3 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions>8){
            txta_display.setText("You have finished! Your score is "+score+" out of 5");
        }
      }
    Sorry if it's a little larger than expected.

  15. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    The posted code does not compile without errors.
    One error is the missing }s at the end
    Another is there are many undefined packages:
    package org.jdesktop.application does not exist

    Another problem is too much IDE generated code.

    Another problem is there is no main() method.


    Please don't post code that you have not compiled, executed and tested. This is just wasting everyone's time.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #16
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    I'm sorry about all of that. However, mistakes happen, it was posted as a rush job sort of thing, and ignoring the dropped }, it runs fine when I execute it. All the generated code and extra methods are there simply because I've never been shown in class which imports/generated code is/is not needed.

    This is my first program I've asked for help online for, and I don't want to end up wasting anyone's time. At this point, I'd just like to fix the error I've been having.

  17. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    I can not compile the code as it is posted. If I can't compile the code I can not test it.

    If you want help, you need to post a SSCCE that compiles, executes and shows the problem.


    it runs fine when I execute it.
    I assume you are talking about some other code. The posted code will not compile without errors.
    If you don't understand my answer, don't ignore it, ask a question.

  18. #18
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    I second Norm's recommendations. If you need our help, post code that we can run, that doesn't have a ton of code unrelated to the problem. It should contain maybe 40 to 150 lines and not hundreds of lines like in your post. Please remember that we are volunteers, that you're not paying us to help you, so we greatly appreciate it when you put int he effort to make it possible for us to help without having to take too much time away from work and family.

  19. #19
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    Alright, that's fair.

    I'm going to trim it down to one button, the variables, and one section of the physical quiz. It comes in at around 145 lines, is that alright?
    Integer[] solutions={0,1,2,4,3,4};
    Integer answer;
    Integer totalquestions=-1;;
    int score, correct;
    Integer step=1;
    Integer A=1;
    Integer B=2;
    Integer C=3;
    Integer D=4;
     
        public Integer buttonPressA(){
     
    answer=A;
     
            if(A.equals(solutions)){           
                totalquestions=totalquestions+1;                  
        }
            else {
                totalquestions=totalquestions+1;
            }    
            System.out.println(""+totalquestions);
            System.out.println("Score: "+score);
            return answer;  
    }
    public SSCCEOfProblemView(SingleFrameApplication app) {
            super(app);
      buttonPressA();
        buttonPressB();
        buttonPressC();
        buttonPressD();
        answer=solutions[0];//Counter iterates once inexpicably, this is a countermeasure
        txta_display.setText("Press an answer button to begin");
     
      if (totalquestions==4){  
        txta_display.setText("What is the slope of a line containing (2,4) and (4,8)?\n A. 2\n B. 3\n C. 13\n D. 1");
        if (answer==solutions[1]){
            score=score+1;
            System.out.println("answer:"+answer);
            System.out.println("solution:"+ java.util.Arrays.toString(solutions));
            System.out.println("question"+totalquestions);
    } 
        else if (totalquestions==5){
             txta_display.setText("What is the slope of the line containing (3,9) and (2,6)?\n A. 4\n B. 3\n C. 6\n D. 1");
             if (answer==solutions[2]){
                 score=score+1; 
             }
        }
        else if(totalquestions==6){
            txta_display.setText("What does a statement like x=4 mean?\n A. nothing\n B. straight line through a y value\n C. No line exists.\nD. The line passes thrrough an x value");
            if (answer==solutions[3]) {
                  score=score+1;
            }
             System.out.println("answer:"+answer);
             System.out.println("solution:"+ java.util.Arrays.toString(solutions));
             System.out.println("1 Score: "+score);
             System.out.println("question"+totalquestions); 
        }
        if (totalquestions==7){
           txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[4]){
                score=score+1;
                System.out.println("answer:"+answer);
                System.out.println("solution:"+ java.util.Arrays.toString(solutions));
            }
            System.out.println("2 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions==8){
        txta_display.setText("What is the slope of  a line segment from (6,12)to (12,36)?\n A. 5\n B. 2\n C.4\n D. 1");
            if (answer==solutions[5]){
                score=score+1;
                 System.out.println("answer:"+answer);
                 System.out.println("solution:"+ java.util.Arrays.toString(solutions));
         }
            System.out.println("3 Score: "+score);
            System.out.println("question"+totalquestions); 
        }
        else if (totalquestions>8){
            txta_display.setText("You have finished! Your score is "+score+" out of 5");
        }
      }

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    That doesn't look like it will compile.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    It's not, now that I've stripped it down. I am honestly trying, I don't know why this keeps happening.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    Strip it, compile it, test it. Then post it.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    Ok, I converted it into something a little more manageable in the ide, and this is the error I get:

    Jan 28, 2013 7:53:36 PM org.jdesktop.application.Application$1 run
    SEVERE: Application class desktopapplication1.DesktopApplication1 failed to launch
    java.lang.NullPointerException
    at desktopapplication1.DesktopApplication1View.<init> (DesktopApplication1View.java:72)
    at desktopapplication1.DesktopApplication1.startup(De sktopApplication1.java:19)
    at org.jdesktop.application.Application$1.run(Applica tion.java:171)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:721)
    at java.awt.EventQueue.access$200(EventQueue.java:103 )
    at java.awt.EventQueue$3.run(EventQueue.java:682)
    at java.awt.EventQueue$3.run(EventQueue.java:680)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 691)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:244)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:147)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:139)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:97)

    Exception in thread "AWT-EventQueue-0" java.lang.Error: Application class desktopapplication1.DesktopApplication1 failed to launch
    at org.jdesktop.application.Application$1.run(Applica tion.java:177)
    at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:721)
    at java.awt.EventQueue.access$200(EventQueue.java:103 )
    at java.awt.EventQueue$3.run(EventQueue.java:682)
    at java.awt.EventQueue$3.run(EventQueue.java:680)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 691)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:244)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:147)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:139)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:97)
    Caused by: java.lang.NullPointerException
    at desktopapplication1.DesktopApplication1View.<init> (DesktopApplication1View.java:72)
    at desktopapplication1.DesktopApplication1.startup(De sktopApplication1.java:19)
    at org.jdesktop.application.Application$1.run(Applica tion.java:171)
    ... 14 more
    I've checked line 72, and it's pregenerated code. Otherwise, there aren't any sort of null values, they all are initialized, so that's not the issue. I've never seen the word severe come up like that before, if that helps at all.

  24. #24
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    It looks like you're still trying to use NetBean's generated code, and I strongly urge you to move away from this. Create your code by hand which will allow you to create a very small runnable Swing GUI that either solves your problems or shows it. You'll also understand Swing much better.

  25. #25
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Counter behaving oddly, skipping large blocks of code& error message

    Ah.

    I do get what you're saying, and I agree that it would help, I'm just under a bit of a time constraint for this one. I need to have it completed by Thursday, and at this point, I'm just trying to come up with something that resembles its intended purpose.

Similar Threads

  1. How to display error message box
    By jasonxman in forum What's Wrong With My Code?
    Replies: 11
    Last Post: August 21st, 2011, 02:47 PM
  2. [SOLVED] Help making an error message.
    By Lost_Secret in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 1st, 2011, 04:48 PM
  3. Strange error message
    By javapenguin in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 11th, 2011, 02:03 PM
  4. What can go wrong if you replace && with & in the following code:
    By scott01 in forum Java Theory & Questions
    Replies: 4
    Last Post: February 12th, 2010, 07:47 AM
  5. help with a error message
    By JavaNoob82 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 23rd, 2010, 02:56 PM