-1

我有 .java 文件。它运行完美。我将其转换为 .jar 文件。然后我尝试使用名为“exe4j”的程序将其转换为 .exe 文件,并成功转换。但是,当我打开这个 .exe 文件时,会出现一条错误消息:

java.util.NoSuchElementException
     at java.util.Scanner.throwFor(Unknown Source)
     at java.util.Scanner.next(Unknown Source)
     at penghitung.persentase(programguru.java:27)
     at programguru.main(programguru.java:361)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at com.exe4j.runtime.LauncherEngine.launch(Unknown Source)
     at com.exe4j.runtime.WinLauncher.main(Unknown Source)

什么意思?我很困惑,因为 .java 文件运行完美。

这是我的代码:

import java.util.*;
import java.io.*;

class penghitung
{
Scanner input = new Scanner(System.in);
int banyak, nilai, jumlah1, jumlah2, jumlah3, jumlah4, a, b, c, d, e, f, aa, bb, cc, dd, rata7;
long pengetahuan;
double numerik, rata1, rata2, rata3, rata4, rata5, rata6;
String pers, absen, predikat, prak, coba;

public void persentase()
{
    System.out.print("\n           *************************************");
    System.out.print("\n           ************START PROGRAM************");
    System.out.print("\n           *************************************");

    System.out.print("\n\nDEFAULT : ");
    System.out.print("\n  Tugas Sekolah  : 10 %");
    System.out.print("\n  Tugas Rumah    : 10 %");
    System.out.print("\n  Ulangan Harian : 20 %");
    System.out.print("\n  UTS            : 25 %");
    System.out.print("\n  UAS            : 30 %");
    System.out.print("\n  Keaktifan      : 5%");

    System.out.print("\n\nApakah anda ingin mengganti persentase tiap kategori? (Y/T) : ");
    pers = input.next();

    a = 10;
    b = 10;
    c = 20;
    d = 25;
    e = 30;
    f = 5;

    if (pers.equals("Y") || pers.equals("y"))
    {
        System.out.print("\n(Dalam persen)");
        System.out.print("\n  Tugas Sekolah  : ");
        a = Integer.parseInt(input.next());
        System.out.print("  Tugas Rumah    : ");
        b = Integer.parseInt(input.next());
        System.out.print("  Ulangan Harian : ");
        c = Integer.parseInt(input.next());
        System.out.print("  UTS            : ");
        d = Integer.parseInt(input.next());
        System.out.print("  UAS            : ");
        e = Integer.parseInt(input.next());
        System.out.print("  Keaktifan      : ");
        f = Integer.parseInt(input.next()); 
    }

    System.out.print("\nBanyak nilai Tugas Sekolah  : ");
    aa = Integer.parseInt(input.next());
    System.out.print("Banyak nilai Tugas Rumah    : ");
    bb = Integer.parseInt(input.next());
    System.out.print("Banyak nilai Ulangan Harian : ");
    cc = Integer.parseInt(input.next());

    System.out.print("\nApakah ada nilai Praktikum? (Y/T) : ");
    prak = input.next();
    if (prak.equals("Y") || prak.equals("y"))
    {   System.out.print("Banyak nilai Praktikum : ");
        dd = Integer.parseInt(input.next());
    }
}   

public void absen()
{
    System.out.print("\n----------------------------------------------------------------");
    System.out.print("\nNomor absen murid : ");
    absen = input.next();
    try 
    {
        FileWriter out = new FileWriter("Data Nilai.txt", true);
        out.write("\r\n#################### NOMOR ABSEN MURID : "+ absen + "\r\n");
        out.close();
    }
    catch (IOException e) 
    {
        e.printStackTrace();
    }
}

public void tugasSekolah()
{
    System.out.print("\nTUGAS SEKOLAH\n");
    try 
    {
        FileWriter out = new FileWriter("Data Nilai.txt", true);
        out.write("\r\nTUGAS SEKOLAH\r\n");

        for (int i = 1; i <= aa; i++)
        {
            if(aa==1)
            {
                System.out.print("  Nilai : ");
                out.write("  Nilai = " + nilai + "\r\n");
                nilai = Integer.parseInt(input.next());
            }
            else 
            {   
                System.out.print("  Nilai ke-" +i+ " : ");
                nilai = Integer.parseInt(input.next());
                out.write("  Nilai ke-" +i+ " = " + nilai + "\r\n");
            }
            jumlah1 += nilai;
            rata1 = jumlah1 / aa * a / 100;   
        }
            out.close();
    }
    catch (IOException e) 
    {
        e.printStackTrace();
    }
}

public void tugasRumah()
{
    System.out.print("\nTUGAS RUMAH\n");
    try 
    {
        FileWriter out = new FileWriter("Data Nilai.txt", true);
        out.write("\r\nTUGAS RUMAH\r\n");

        for (int i=1; i<=bb; i++)
        {
            if(bb==1)
            {
                System.out.print("  Nilai : ");
                out.write("  Nilai = " + nilai + "\r\n");
                nilai = Integer.parseInt(input.next());
            }
            else 
            {
                System.out.print("  Nilai ke-" +i+ " : ");
                nilai = Integer.parseInt(input.next());
                out.write("  Nilai ke-" +i+ " = " + nilai + "\r\n");
            }
            jumlah2 += nilai;
            rata2 = jumlah2 / bb * b / 100;
        }
            out.close();
    } 
    catch (IOException e) 
    {
        e.printStackTrace();
    } 
}

public void ulanganHarian()
{
    System.out.print("\nULANGAN HARIAN\n");
    try 
    {
        FileWriter out = new FileWriter("Data Nilai.txt", true);
        out.write("\r\nULANGAN HARIAN\r\n");

        for (int i=1; i<=cc; i++)
        {
            if(cc==1)
            {
                System.out.print("  Nilai : ");
                out.write("  Nilai = " + nilai + "\r\n");
                nilai = Integer.parseInt(input.next());
            }
            else 
            {
                System.out.print("  Nilai ke-" +i+ " : ");
                nilai = Integer.parseInt(input.next()); 
                out.write("  Nilai ke-" +i+ " = " + nilai + "\r\n");
            }
            jumlah3 += nilai;
            rata3 = jumlah3 / cc * c / 100;
        }
            out.close();
    } 
    catch (IOException e) 
    {
        e.printStackTrace();
    } 
}

public void uts()
{
    System.out.print("\nUTS\n");
    System.out.print(" Nilai : ");
    nilai = Integer.parseInt(input.next());
    rata4 = nilai * d / 100;
    try 
    {
        FileWriter out = new FileWriter("Data Nilai.txt", true);
        out.write("\r\nUTS\r\n");
        out.write("  Nilai = " + nilai + "\r\n");
        out.close();
    }
    catch (IOException e) 
    {
        e.printStackTrace();
    } 
}

public void uas()
{
    System.out.print("\nUAS\n");
    System.out.print(" Nilai : ");
    nilai = Integer.parseInt(input.next()); 
    rata5 = nilai * e / 100;
    try 
    {
        FileWriter out = new FileWriter("Data Nilai.txt", true);
        out.write("\r\nUAS\r\n");
        out.write("  Nilai = " + nilai + "\r\n");
        out.close();
    }
    catch (IOException e) 
    {
        e.printStackTrace();
    } 
}

public void keaktifan()
{
    System.out.print("\nKEAKTIFAN\n");
    System.out.print(" Nilai : ");
    nilai = Integer.parseInt(input.next());
    rata6 = nilai * f / 100;
    try 
    {
        FileWriter out = new FileWriter("Data Nilai.txt", true);
        out.write("\r\nKEAKTIFAN\r\n");
        out.write("  Nilai = " + nilai + "\r\n");
        out.close();
    }
    catch (IOException e) 
    {
        e.printStackTrace();
    } 
}   

public void praktikum()
{
    if (prak.equals("Y") || prak.equals("y"))
    {
        System.out.print("\nPRAKTIKUM\n");
        try 
        {
            FileWriter out = new FileWriter("Data Nilai.txt", true);
            out.write("\r\nPRAKTIKUM\r\n");

            for (int i=1; i<=dd; i++)
            {
                if(dd==1)
                {
                    System.out.print("  Nilai : ");
                    out.write("  Nilai = " + nilai + "\r\n");
                    nilai = Integer.parseInt(input.next());
                }
                else 
                {
                    System.out.print(" Nilai ke-" +i+ " : ");
                    nilai = Integer.parseInt(input.next()); 
                    out.write("  Nilai ke-" +i+ " = " + nilai + "\r\n");
                }
                jumlah4 += nilai;
                rata7 = Math.round(jumlah4 / dd);
            }
                out.write("\r\n>>> NILAI PRAKTIK: " +rata7);
                out.close();
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
        } 

        System.out.print("\n\n***NILAI PRAKTIK***     : "+rata7);

    }
}   

public void pengetahuan()
{
    System.out.print("\n***NILAI PENGETAHUAN*** : ");
    pengetahuan = Math.round(rata1 + rata2 + rata3 + rata4 + rata5 + rata6);
    System.out.print(pengetahuan);
    try 
    {
        FileWriter out = new FileWriter("Data Nilai.txt", true);
        out.write("\r\n>>> NILAI PENGETAHUAN: " +pengetahuan);
        out.close();
    }
    catch (IOException e) 
    {
        e.printStackTrace();
    } 
}

public void predikat()
{
    if(pengetahuan > 75)
    {
        predikat = "TINGGI";
    } else if(pengetahuan == 75)
    {
        predikat = "SEDANG";
    } else
    {
        predikat = "KURANG";
    }
    System.out.print("\n***PREDIKAT***          : " +predikat);
    try 
    {
        FileWriter out = new FileWriter("Data Nilai.txt", true);
        out.write("\r\n>>> PREDIKAT : " +predikat+ "\r\n");
        out.close();
    }
    catch (IOException e) 
    {
        e.printStackTrace();
    } 
}

public void menu()
{
    System.out.print("\n\nTambah lagi? (Y/T) : ");
    coba = input.next();

    if (coba.equals("Y") || coba.equals("y"))
    {
        absen();
        tugasSekolah();
        tugasRumah();
        ulanganHarian();
        uts();
        uas();
        keaktifan();
        praktikum();
        pengetahuan();
        predikat();
        menu();
    }
    else 
    {
        System.out.print("\n           **************************************");
        System.out.print("\n           *************EXIT PROGRAM*************");
        System.out.print("\n           **************************************");
    }
}
}


public class programguru
{
public static void main (String args[])
{       
    penghitung penghitungku = new penghitung();

    //PERSENTASE NILAI
    penghitungku.persentase();

    //NOMOR ABSEN
    penghitungku.absen();

    //NILAI TUGAS SEKOLAH
    penghitungku.tugasSekolah();

    //NILAI TUGAS RUMAH
    penghitungku.tugasRumah();

    //NILAI ULANGAN HARIAN
    penghitungku.ulanganHarian();

    //NILAI UTS
    penghitungku.uts();

    //NILAI UAS
    penghitungku.uas();

    //NILAI KEAKTIFAN
    penghitungku.keaktifan();

    //NILAI PRAKTIKUM
    penghitungku.praktikum();

    //NILAI PENGETAHUAN
    penghitungku.pengetahuan();

    //PREDIKAT
    penghitungku.predikat();

    //MENU TAMBAH
    penghitungku.menu();
}
}
4

1 回答 1

1

这里只是猜测,因为信息不完整:错误消息表明您在第一次执行“input.next();”的位置有错误 除了表明“没有这样的元素”之外。如果您在 Windows 上,并且您通过双击文件夹中的图标来启动此可执行文件,那么您必须弄清楚“System.in”的来源。Windows 不会自动打开命令窗口供您输入;如果你想要那样,你必须以不同的方式运行它。

于 2012-12-31T17:16:16.460 回答