由于某种原因,我一直无法弄清楚,我已经工作了一段时间的程序现在没有运行。这是我收到的错误消息:
我在它工作的时间和现在之间所做的一切都是添加另一个类,但即使删除它之后,错误信息仍然在这里。 Netbeans也没有帮助,代码中没有任何标记为红色的错误。我还是Java的初学者,所以我不知道找到错误需要多少,所以这里是所有的代码:
public class ChooseYourOwn {
static class Character {
private static int str;
public Character() {
int str = 0;
int spd = 0;
int agl = 0;
int def = 0;
int mag = 0;
int wil = 0;
int mp = 0;
int hp = 0;
}
private Character(String name) {
}
}
/**
*
* @param args
* @return
*/
public static int main(String[] args) {
//set up character
System.out.println("Choose a class:");
String [] genusOptions;
genusOptions = new String[] {"\n1-Warrior\n2-Mage\n3-Thief"};
System.out.println(Arrays.toString(genusOptions));
Scanner input1 = new Scanner(System.in);
String genus;
genus = input1.nextLine();
System.out.println("Your character's stats are:");
switch (genus) {
case "1":
{
String[] array = new String[] {"\nStrength-15\nSpeed-5\nAgility-5\nDefense-10\nMagicDamage-5\nMagicDefense-0\nMagicPoints-5\nHitPoints-15\n"};
System.out.println(Arrays.toString(array));
int str = 5;
int spd = 2;
int agl = 2;
int def = 5;
int mag = 0;
int wil = 0;
int mp = 0;
int hp = 10;
break;
}
case "2":
{
String[] array = new String[] {"\nStrength-5\nSpeed-5\nAgility-5\nDefense-0\nMagicDamage-15\nMagicDefense-10\nMagicPoints-15\nHitPoints-5\n"};
System.out.println(Arrays.toString(array));
int str = 5;
int spd = 5;
int agl = 5;
int def = 0;
int mag = 10;
int wil = 10;
int mp = 15;
int hp = 5;
break;
}
case "3":
{
String[] array = new String[] {"\nStrength-10\nSpeed-15\nAgility-15\nDefense-10\nMagicDamage-10\nMagicDefense-5\nMagicPoints-10\nHitPoints-10\n"};
System.out.println(Arrays.toString(array));
int str = 10;
int spd = 15;
int agl = 15;
int def = 10;
int mag = 10;
int wil = 5;
int mp = 10;
int hp = 10;
break;
}
}
String[] array = new String[] {"\n1-Move\n2-Rest\n3-Attack\n4-Run\n5-Activate lever/button/chest\n6-Inventory\n7-Skills"};
System.out.println("Choose a number to continue");
System.out.println(Arrays.toString(array));
Scanner input2;
input2 = new Scanner(System.in);
String action;
action = input2.nextLine();
switch (action) {
case "1":
{
System.out.println("");
//not done yet
break;
}
case "2":
{
System.out.println("");
//Rest, restores some health
break;
}
case "3":
{
System.out.println("");
int max = 100;
int min = 0;
Random rand = new Random();
int randomNum = rand.nextInt((max - min) + 1) + min;
int damage = 0;
if (10 > randomNum) {
damage = (Character.str/100) * 10;
} else if (20 > randomNum) {
damage = (Character.str/100) * 20;
} else if (30 > randomNum) {
damage = (Character.str/100) * 30;
} else if (40 > randomNum) {
damage = (Character.str/100) * 40;
} else if (50 > randomNum) {
damage = (Character.str/100) * 50;
} else if (60 > randomNum) {
damage = (Character.str/100) * 60;
} else if (70 > randomNum) {
damage = (Character.str/100) * 70;
} else if (80 > randomNum) {
damage = (Character.str/100) * 80;
} else if (90 > randomNum) {
damage = (Character.str/100) * 90;
} else if (100 > randomNum) {
damage = Character.str;
}
System.out.println( damage );
break;
}
case "4":
{
System.out.println("");
//not done yet
break;
}
case "5":
{
System.out.println("");
//not done yet
break;
}
case "6":
{
System.out.println("");
//not done yet
break;
}
case "7":
{
System.out.println("");
//not done yet
}
}
return (0);
}
}
之前有过类似的问题,但没有一个问题有帮助,其他问题也不清楚。非常感谢一个好的和连贯的答案,谢谢。
答案 0 :(得分:3)
在Java中,主要方法签名是 public static void main(String[] args)
,但是在您的代码中,您使用的是public static int main(String[] args)
。
答案 1 :(得分:2)
Java主要方法声明如下:
public static void main(String[] args) {
...
}
找到更多信息
答案 2 :(得分:2)
您无法更改main
的返回类型。此,
public static int main(String[] args)
必须是(每个值得Wikipedia article on Entry point
)
public static void main(String[] args)
public static void main(String... args)
public static void main(String args[])
所有这些都是void
,如果您需要设置UNIX
样式返回类型,可以使用System.exit(int);
来引用Javadoc
终止当前运行的Java虚拟机。该参数用作状态代码;按照惯例,非零状态代码表示异常终止。