因此,当我尝试在 Windows cmd 中运行非常简单的基于文本的 jar 时出现此错误:
Exception in thread "main" java.lang.IllegalAccessException: Class
org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader can not access
a member of class me.Puffinlump.ItemDivider.Minecraftitemsdivider
with modifiers "public static"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:109)
at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:261)
at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:253)
at java.lang.reflect.Method.invoke(Method.java:599)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
它在 Eclipse 中工作正常,但与其他任何东西都不兼容。我不知道如何为它制作一个允许输入和输出或任何控制台的控制台。基本上我无法制作控制台。
这是我的代码:
package me.Puffinlump.ItemDivider;
import java.util.Scanner;
class Minecraftitemsdivider {
public static void main(String args[]) {
Scanner keyboard = new Scanner(System.in);
//Values for the script
String Itemname;
String Thingname;
int Iammount;
int things;
int Itemsperthings;
//Question
System.out.print("What is the name of your item? What type of things are you giving them to e.g. Player? How many are you giving? How many things are you dividing it among?");
//The start of the input values.
Itemname = keyboard.next();
Thingname = keyboard.next();
Iammount = keyboard.nextInt();
things = keyboard.nextInt();
//The end of the input values.
//Math
Itemsperthings = Iammount / things;
//Printer
System.out.print("Each ");
System.out.print(Thingname);
System.out.print(" gets ");
System.out.print(Itemsperthings);
System.out.print(" ");
System.out.print(Itemname);
System.out.print("s.");
//Ending process
keyboard.close();
}
}
最佳答案
你的类需要是public
,所以改变
class Minecraftitemsdivider
到
public class Minecraftitemsdivider
关于java - 基于文本的 jar 文件在 Windows cmd 错误中运行。这怎么能解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27667556/