Question

I made a .jar file using NetBeans and when I try to run it on a different PC, it giver me this message:

enter image description here

It isn't a typo or anything because I made several other .jar files and got the same response. If the code matters, then here is the code:

    package java_blackjack;

    import java.awt.CardLayout;
    import java.util.Arrays;
    import java.util.Scanner;

    class globals{
            static int[] dealer = new int[5];
            static int[] player = new int[5];
            static int number = 0;
        }

    public class java_blackjack extends javax.swing.JFrame {

        public java_blackjack() {
            initComponents();
        }

        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {

            main = new javax.swing.JPanel();
            panel1 = new javax.swing.JPanel();
            title = new javax.swing.JLabel();
            begin_button = new javax.swing.JToggleButton();
            instructions_button = new javax.swing.JButton();
            quit_button = new javax.swing.JButton();
            panel2 = new javax.swing.JPanel();
            jLabel2 = new javax.swing.JLabel();
            jScrollPane1 = new javax.swing.JScrollPane();
            panel2_textarea = new javax.swing.JTextArea();
            hit_button = new javax.swing.JButton();
            stand_button = new javax.swing.JButton();
            results_panel = new javax.swing.JPanel();
            results_title = new javax.swing.JLabel();
            jScrollPane2 = new javax.swing.JScrollPane();
            results_info = new javax.swing.JTextArea();
            menu_button = new javax.swing.JButton();
            instructions = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            jScrollPane3 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();
            jButton1 = new javax.swing.JButton();

            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

            main.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
            main.setName("main"); // NOI18N
            main.setLayout(new java.awt.CardLayout());

            title.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
            title.setForeground(new java.awt.Color(0, 0, 204));
            title.setText("Blackjack game");

            begin_button.setText("BEGIN");
            begin_button.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    begin_buttonActionPerformed(evt);
                }
            });

            instructions_button.setText("INSTRUCTIONS");
            instructions_button.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    instructions_buttonActionPerformed(evt);
                }
            });

            quit_button.setText("QUIT");
            quit_button.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    quit_buttonActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(panel1);
            panel1.setLayout(panel1Layout);
            panel1Layout.setHorizontalGroup(
                panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
                    .addContainerGap(108, Short.MAX_VALUE)
                    .addComponent(title)
                    .addGap(101, 101, 101))
                .addGroup(panel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(instructions_button, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(begin_button, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(quit_button, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addContainerGap())
            );
            panel1Layout.setVerticalGroup(
                panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panel1Layout.createSequentialGroup()
                    .addComponent(title)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(begin_button)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(instructions_button)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(quit_button)
                    .addGap(0, 11, Short.MAX_VALUE))
            );

            main.add(panel1, "panel1");

            jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
            jLabel2.setForeground(new java.awt.Color(0, 0, 255));
            jLabel2.setText("The dealer has chosen his cards");

            panel2_textarea.setColumns(20);
            panel2_textarea.setRows(5);
            panel2_textarea.setText("You: ");
            jScrollPane1.setViewportView(panel2_textarea);

            hit_button.setText("HIT");
            hit_button.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    hit_buttonActionPerformed(evt);
                }
            });

            stand_button.setText("STAND");
            stand_button.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    stand_buttonActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout panel2Layout = new javax.swing.GroupLayout(panel2);
            panel2.setLayout(panel2Layout);
            panel2Layout.setHorizontalGroup(
                panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(panel2Layout.createSequentialGroup()
                            .addGap(0, 53, Short.MAX_VALUE)
                            .addComponent(jLabel2))
                        .addComponent(jScrollPane1))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(hit_button, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(stand_button, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addContainerGap())
            );
            panel2Layout.setVerticalGroup(
                panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panel2Layout.createSequentialGroup()
                    .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(panel2Layout.createSequentialGroup()
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel2Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(hit_button)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(stand_button)))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );

            main.add(panel2, "panel2");

            results_title.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
            results_title.setForeground(new java.awt.Color(0, 0, 255));
            results_title.setText("THE RESULTS GO HERE");

            results_info.setColumns(20);
            results_info.setRows(5);
            results_info.setText("What ever results there may be,\nthey will appear here.");
            jScrollPane2.setViewportView(results_info);

            menu_button.setText("MENU");
            menu_button.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    menu_buttonActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout results_panelLayout = new javax.swing.GroupLayout(results_panel);
            results_panel.setLayout(results_panelLayout);
            results_panelLayout.setHorizontalGroup(
                results_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(results_panelLayout.createSequentialGroup()
                    .addGap(71, 71, 71)
                    .addComponent(results_title, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(73, Short.MAX_VALUE))
                .addGroup(results_panelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane2)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(menu_button)
                    .addContainerGap())
            );
            results_panelLayout.setVerticalGroup(
                results_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(results_panelLayout.createSequentialGroup()
                    .addComponent(results_title, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(results_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(menu_button, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addContainerGap())
            );

            main.add(results_panel, "results_panel");

            jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
            jLabel1.setForeground(new java.awt.Color(0, 0, 255));
            jLabel1.setText("Instructions");

            jTextArea1.setColumns(20);
            jTextArea1.setRows(5);
            jTextArea1.setText("You have to get 21 or closer to 21 than the dealer.\nIf you go over 21, you lose. Click hit to pull another \ncard and stand to finish.");
            jScrollPane3.setViewportView(jTextArea1);

            jButton1.setText("Menu");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout instructionsLayout = new javax.swing.GroupLayout(instructions);
            instructions.setLayout(instructionsLayout);
            instructionsLayout.setHorizontalGroup(
                instructionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(instructionsLayout.createSequentialGroup()
                    .addGroup(instructionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(instructionsLayout.createSequentialGroup()
                            .addGap(151, 151, 151)
                            .addComponent(jLabel1)
                            .addGap(0, 142, Short.MAX_VALUE))
                        .addGroup(instructionsLayout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jScrollPane3)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton1)))
                    .addContainerGap())
            );
            instructionsLayout.setVerticalGroup(
                instructionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(instructionsLayout.createSequentialGroup()
                    .addComponent(jLabel1)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(instructionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addGroup(instructionsLayout.createSequentialGroup()
                            .addGap(0, 65, Short.MAX_VALUE)
                            .addComponent(jButton1)))
                    .addContainerGap())
            );

            main.add(instructions, "instructions");

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(main, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(main, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );

            main.getAccessibleContext().setAccessibleName("main");

            pack();
        }// </editor-fold>                        

        private void menu_buttonActionPerformed(java.awt.event.ActionEvent evt) {                                            
            CardLayout cl = (CardLayout)(main.getLayout());
            cl.show(main, "panel1");
        }                                           

        private void begin_buttonActionPerformed(java.awt.event.ActionEvent evt) {                                             
            game.begin_game();
        }                                            

        private void hit_buttonActionPerformed(java.awt.event.ActionEvent evt) {                                           
            game.hit(globals.number);
            globals.number += 1;
            game.player_turn_2();
        }                                          

        private void stand_buttonActionPerformed(java.awt.event.ActionEvent evt) {                                             
            game.stand();
        }                                            

        private void quit_buttonActionPerformed(java.awt.event.ActionEvent evt) {                                            
            System.exit(0);
        }                                           

        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            CardLayout cl = (CardLayout)(main.getLayout());
            cl.show(main, "panel1");
        }                                        

        private void instructions_buttonActionPerformed(java.awt.event.ActionEvent evt) {                                                    
            CardLayout cl = (CardLayout)(main.getLayout());
            cl.show(main, "instructions");
        }                                                   


        class game_properties {
            Scanner field = new Scanner(System.in);
            public void begin_game(){
                globals.dealer = new int[5];
                globals.player = new int[5];
                globals.number = 0;
                dealer_turn();
            }
            public int shuffle(){
                int current = (int)(1+Math.random()*10);
                return current;
            }
            public void dealer_turn(){
                int number = 0;
                int nowNum = 0;
                int mode = 0;
                String info = "";
                while (number < 14){
                    globals.dealer[nowNum] = shuffle();
                    number += globals.dealer[nowNum];
                    nowNum += 1;
                }
                int dealer_cards = 0;
                for (int i=0;i<5;i++){
                    dealer_cards += globals.dealer[i];
                }
                if (dealer_cards == 21){
                    info = ("Dealer wins. he has 21.");
                    CardLayout cl = (CardLayout)(main.getLayout());
                    cl.show(main, "results_panel");
                    panel2_textarea.setText(info);
                } else if (dealer_cards > 21){
                    info = ("You win, dealer went bust.");
                    CardLayout cl = (CardLayout)(main.getLayout());
                    cl.show(main, "results_panel");
                    panel2_textarea.setText(info);
                } else if (dealer_cards < 21){
                    info = ("Dealer has chosen his cards.");
                    CardLayout cl = (CardLayout)(main.getLayout());
                    cl.show(main, "panel2");
                    panel2_textarea.setText(info);
                    player_turn();
                }

            }

            public void hit(int num){
                    globals.player[num] = shuffle();
                }

            public void stand(){
                    String info = "";
                    int dealerNumber = 0;
                    int playerNumber = 0;
                    for (int i=0;i<5;i++){
                        dealerNumber += globals.dealer[i];
                    }
                    for (int i=0;i<5;i++){
                        playerNumber += globals.player[i];
                    }
                    //System.out.println("You: "+Arrays.toString(globals.player)+" total: "+playerNumber);
                    //System.out.println("Dealer: "+Arrays.toString(globals.dealer)+" total: "+dealerNumber);
                    if (playerNumber == dealerNumber){
                        info = ("Push, you both got the same.\nYou: "+playerNumber
                                + "\nDealer: "+dealerNumber);
                    } else if (playerNumber > dealerNumber){
                        info = ("You win! You have more than the dealer.\nYou: "+playerNumber
                                + "\nDealer: "+dealerNumber);
                    } else if(dealerNumber > playerNumber) {
                        info  = ("You lose, the dealer has more than you.\nYou: "+playerNumber
                                + "\nDealer: "+dealerNumber);
                    }
                    CardLayout cl = (CardLayout)(main.getLayout());
                    cl.show(main, "results_panel");
                    results_info.setText(info);
                }

            public void player_turn(){
                for (int i=0;i<2;i++){
                    globals.player[i] = shuffle();
                    globals.number += 1;
                }
                player_turn_2();
            }
            public void player_turn_2(){
                int sum = 0;
                String info = "";
                for (int i=0;i<5;i++){
                    sum += globals.player[i];
                }
                if (sum < 21) {
                    info = ("Your total is: "+sum+"\nWhat do you wish to do? hit or stand?");
                    CardLayout cl = (CardLayout)(main.getLayout());
                    cl.show(main, "panel2");
                    panel2_textarea.setText(info);
                } else if(sum == 21){
                    info = ("Your total is: "+sum+"\nYou win!");
                    CardLayout cl = (CardLayout)(main.getLayout());
                    cl.show(main, "results_panel");
                    results_info.setText(info);
                } else if(sum > 21){
                    info = ("Your total is: "+sum+"\nYou went bust!");
                    CardLayout cl = (CardLayout)(main.getLayout());
                    cl.show(main, "results_panel");
                    results_info.setText(info);
                }
            }

        }

        // end your code here
        game_properties game = new game_properties();
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
             * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(java_blackjack.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(java_blackjack.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(java_blackjack.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(java_blackjack.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>


            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new java_blackjack().setVisible(true);
                }
            });
        }

        // Variables declaration - do not modify                     
        private javax.swing.JToggleButton begin_button;
        private javax.swing.JButton hit_button;
        private javax.swing.JPanel instructions;
        private javax.swing.JButton instructions_button;
        private javax.swing.JButton jButton1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JScrollPane jScrollPane3;
        private javax.swing.JTextArea jTextArea1;
        private javax.swing.JPanel main;
        private javax.swing.JButton menu_button;
        private javax.swing.JPanel panel1;
        private javax.swing.JPanel panel2;
        private javax.swing.JTextArea panel2_textarea;
        private javax.swing.JButton quit_button;
        private javax.swing.JTextArea results_info;
        private javax.swing.JPanel results_panel;
        private javax.swing.JLabel results_title;
        private javax.swing.JButton stand_button;
        private javax.swing.JLabel title;
        // End of variables declaration                   
    }

someone please help me. this problem is limiting my java programs

Was it helpful?

Solution

The java version that you compile with should be less than or equal to the java version that you are using to execute.

For ex if you compile something with Java 1.7.1 , it can only run on JRE's 1.7.1 and higher. It will fail with the same exception if you run it on java 1.7.0

OTHER TIPS

That's a java version mismatch.

It looks like the jar file you created was build for Java 8.

Try using JRE 8.0 and see if it works.

4 months before even i faced similar issue, this is because of the java minor version mismatch. We developers may be under conception only mismatch happens between 1.6 and 1.7 versions. But it happens between minor versions like 1.7.1 and 1.7.20 also. Please check it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top