如何在Eclipse中运行简单的Java程序? [英] How to Run a Simple Java Program in Eclipse?

查看:103
本文介绍了如何在Eclipse中运行简单的Java程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你可能从问题本身来理解,我是Java的新手。
我得到一个练习来写一个Java程序,它接收一个字符,打印它和Unicode表中的下一个字符。

As you can probably understand from the question itself, I'm new to Java. I was given an exercise to write a Java program which receives a character, prints it and the next character in the Unicode table.

现在,

public static void main(String[] args){
    char c = args[0].charAt(0);
    char c1 = (char)(c + 1);
    System.out.println(c + "\t" + c1);
}



我理解这个代码的基本思想,但我试图运行代码在Eclipse中我得到一个恼人的错误:

I understand basic idea of this code, but I'm trying to run this code in Eclipse I get an annoying error:

线程main中的异常java.lang.ArrayIndexOutOfBoundsException:0
MainClass.main(MainClass.java: 9)

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at MainClass.main(MainClass.java:9)

注意:我还没有运行一个Java程序,实际上接收的东西作为参数,所以我猜这是一个愚蠢的初学者的错误...这里是完整的我试图在Eclipse中编译的代码:

Note: I have yet to run a Java program that actually receives something as a parameter so I guess it's a stupid beginners' mistake... Here is the full code that I tried to compile in Eclipse:

public class MainClass {

    /**
     * @param args
     */

    public static void main(String[] args){
        char c = args[0].charAt(0);
        char c1 = (char)(c + 1);
        System.out.println(c + "\t" + c1);
    }
}

提前感谢

推荐答案


  • 从菜单中选择运行 - >运行配置。

  • 在左侧列表中搜索您的项目,然后选择它。

  • 选择右侧的参数标签。

  • 单击运行

    • Select "Run -> Run Configurations" from the menu.
    • Search for you project in the list on the left and select it.
    • Select the "Arguments" tab on the right.
    • Write the argument you want to pass to the programm in "Programm arguments".
    • Click "Run"
    • 这篇关于如何在Eclipse中运行简单的Java程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆