我使用NetBeans创建了一个.jar文件,当我尝试在另一台PC上运行它时,它给了我这条消息:
这不是一个错字或任何东西,因为我制作了几个其他.jar文件并获得了相同的响应。如果代码很重要,那么这里是代码:
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
}
有人请帮帮我。这个问题限制了我的java程序
答案 0 :(得分:0)
这是一个java版本不匹配。
您创建的jar文件看起来像是为Java 8构建的。
尝试使用JRE 8.0并查看它是否有效。
答案 1 :(得分:0)
您编译的java版本应小于或等于您用于执行的Java版本。
例如,如果您使用Java 1.7.1 编译某些东西,它只能在JRE的1.7.1及更高版本上运行。如果您在 java 1.7.0
上运行,则失败会出现相同的异常答案 2 :(得分:0)
在我面临类似问题之前4个月,这是因为java次要版本不匹配。我们的开发人员可能只是在构思中,只有1.6和1.7版本之间发生不匹配。但它也发生在1.7.1和1.7.20等次要版本之间。请检查一下。