有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

基于java文本的jar文件在windows cmd中运行时出错。这个问题怎么解决?

因此,当我尝试在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();
    }


}

共 (1) 个答案

  1. # 1 楼答案

    你的类需要是public,所以改变一下

    class Minecraftitemsdivider
    

    public class Minecraftitemsdivider