After I convert JAR file to EXE, program throws exception-Collection of common programming errors
i have .java file. It runs perfectly. I convert it to .jar file. Then i try to convert it to .exe file using program named “exe4j”, and successfully converted. But, when i open this .exe file there is an error message:
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)
What is the meaning? I’m confused because the .java file runs perfectly.
Here is my code:
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 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();
}
}
-
Just guessing here, since there is incomplete information: the error message indicates that you have an error about where you first do an “input.next();” in addition to indicating that there is “no such element”. If you are on Windows, and you are starting this executable by double-clicking an icon in a folder, then you have to figure out where “System.in” will come from. Windows will not automatically open up a command window for you to type input; if you want that, you have to run it a different way.