java,“输入程序参数”错误?

时间:2012-04-24 21:28:48

标签: java compilation

我是java编程的新手。下面我有我的程序和不断出现的错误。我不知道这意味着什么,如果有人可以帮助我。我正在使用深红色的编辑器,我的程序编译正常,当一个窗口问我“输入程序参数”,这个错误出现。如果有人可以请向我解释这是什么意思。谢谢。 //我的程序

package test.rim.bbapps.testcase.lib;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class michaeltictactoe2 implements ActionListener {

    /* Instance variables */

    private JFrame window = new JFrame (" TicTacToe");
    private JButton button1 = new JButton ("") ;
    private JButton button2 = new JButton ("") ;
    private JButton button3 = new JButton ("") ;
    private JButton button4 = new JButton ("") ;
    private JButton button5 = new JButton ("") ;
    private JButton button6 = new JButton ("") ;
    private JButton button7 = new JButton ("") ;
    private JButton button8 = new JButton ("") ;
    private JButton button9 = new JButton ("") ;
    private String letter = "";
    private int count = 0; 
    private boolean win = false; 

    public michaeltictactoe2 () {
        //* Create Window * /
        window.setSize (300,300);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setLayout ( new GridLayout (3, 3));

        /* Adding buttons to the window*/
        window.add(button1);
        window.add(button2);
        window.add(button3);
        window.add(button4);
        window.add(button5);
        window.add(button6);
        window.add(button7);
        window.add(button8);
        window.add(button9);

        /* Add the action listener to the Button */
        button1.addActionListener(this);
        button2.addActionListener(this);
        button3.addActionListener(this);
        button4.addActionListener(this);
        button5.addActionListener(this);
        button6.addActionListener(this);
        button7.addActionListener(this);
        button8.addActionListener(this);
        button9.addActionListener(this);

        //* make the window visible * /
        window.setVisible (true) ;
    }

    public void actionPerformed (ActionEvent a) {
        count++;

        /* Calculate who's turn it is */
        if (count == 1 || count == 3|| count == 5 || count == 7 || count == 9) {
            letter = "X"; 
        } else if ( count == 2 || count == 4 || count  == 6 || count == 8  ) {
            letter = "O";   
        }

        /* Display X's or O's on the buttons */
        if ( a.getSource () == button1) {
            button1.setText ( letter ) ;
            button1.setEnabled (false);
        } else if (a.getSource () == button2) {
            button2.setText(letter);
            button2.setEnabled(false); 
        } else if (a.getSource () == button3) {
            button3.setText(letter);
            button3.setEnabled(false); 
        } else if (a.getSource () == button4) {
            button4.setText(letter);
            button4.setEnabled(false); 
        } else if (a.getSource () == button5) {
            button5.setText(letter);
            button5.setEnabled(false); 
        } else if (a.getSource () == button6) {
            button6.setText(letter);
            button6.setEnabled(false); 
        } else if (a.getSource () == button7) {
            button7.setText(letter);
            button7.setEnabled(false); 
        } else if (a.getSource () == button8) {
            button8.setText(letter);
            button8.setEnabled(false); 
        } else if (a.getSource () == button9) {
            button9.setText(letter);
            button9.setEnabled(false);
        }

        // * Determine who won */
        // horizontal wins
        if ( button1.getText () == button2.getText ()
            && button2.getText () == button3.getText ()
            && button1.getText () != "") {

            win = true;

        } else if ( button4.getText () == button5.getText ()
                    && button5.getText () == button6.getText ()
                    && button4.getText () != "") {
            win = true;

        } else if ( button7.getText () == button8.getText ()
                &&    button8.getText () == button9.getText ()
                &&    button7.getText () != "") {
                win = true;

            // Verticle wins 
        } else if (button1.getText() == button4.getText ()
               && button4.getText() == button7.getText ()
               && button1.getText() != "") {
               win = true; 

        } else if (button2.getText() == button5.getText()
                &&  button5.getText() == button8.getText()
                &&  button2.getText() != "") {
               win = true;
        } else if ( button3.getText() == button6.getText()
                &&   button6.getText() == button9.getText()
                &&   button9.getText() != "") {
               win = true ;

        // Diagonal wins 
        } else if (button1.getText() == button5.getText()
                && button5.getText() == button9.getText()
                && button1.getText() != "") {
                win = true; 

         } else if (button3.getText() == button5.getText()
                 && button5.getText() == button7.getText()
                 && button3.getText() != "") {
                win = true;
         } else {
                win = false ;
         }

        /* show a dialog is someone wins or the game is tie*/
        if ( win == true) {
            JOptionPane.showMessageDialog(null, letter + " YOU WIN!");
        } else if (count == 9 && win == false) {
            JOptionPane.showMessageDialog ( null , " Tie Game!" ) ;  
        }
    }

    public static void main (String [] args) {
        new michaeltictactoe2 () ;
    }
}

错误:

---------- Capture Output ----------
> "C:\Program Files\Java\jdk1.6.0_22\bin\java.exe" michaeltictactoe1
java.lang.NoClassDefFoundError: michaeltictactoe1 (wrong name: test/rim/bbapps/testcase/lib/michaeltictactoe1)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: michaeltictactoe1.  Program will exit.
Exception in thread "main" 
> Terminated with exit code 1.
再次感谢。

2 个答案:

答案 0 :(得分:2)

你正在编译michaeltictactoe1,类名是michaeltictactoe2

编译
javac michaeltictactoe2.java

然后用

运行
java michaeltictactoe2

阅读http://www.oracle.com/technetwork/java/compile-136656.html

答案 1 :(得分:1)

看起来类名与文件名不匹配(michaeltictactoe1与michaeltictactoe2)