java - 基于文本的 jar 文件在 Windows cmd 错误中运行。这怎么能解决?

标签 java

因此,当我尝试在 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/

相关文章:

java - float 值上的 TimeUnit

java - struts 1 form bean线程安全吗?

java - com.hazelcast.nio.serialization.HazelcastSerializationException

java - 有人可以解释一下我在这个二维数组游戏中做错了什么吗

java - 列出 Evernote 垃圾箱的内容

java - 为什么 Java 告诉我我的小程序包含签名和未签名的代码?

java - 编译 Maven 项目的默认 Vaadin 小部件

java - 如何让线程停止相互阻塞写入磁盘上的日志文件?

java - 使用java构建字典

java - Java 等于多个值