大家好! 夥計們我有一個簡單的代碼的問題。我找不到錯在哪裏。每次我想運行的程序中,我得到這個消息:關於java.util.InputMismatchException的一些東西?
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at TeamMMA.<init>(TeamMMA.java:17)
at ShowTeamFrame.main(ShowTeamFrame.java:8)
這是一個簡單的PROGRAMM,我希望有一個開始:
import java.text.DecimalFormat;
public class MMACompetitors {
private String name;
private double average;
public MMACompetitors(String name, double average){
this.name=name;
this.average=average;
}
public String getName(){
return name;
}
public double getAverage(){
return average;
}
public String getAverageString(){
DecimalFormat decFormat=new DecimalFormat();
decFormat.setMaximumIntegerDigits(0);
decFormat.setMaximumFractionDigits(3);
decFormat.setMinimumFractionDigits(3);
return decFormat.format(average);
}
}
第二類:
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.GridLayout;
@SuppressWarnings("serial")
public class TeamMMA extends JFrame{
public TeamMMA() throws IOException{
MMACompetitors mma;
@SuppressWarnings("resource")
Scanner keyboard = new Scanner(new File("MMAStatisticBullyTeam.txt"));
for(int num=1;num <=5;num++){
mma=new MMACompetitors(keyboard.nextLine(),keyboard.nextDouble());
keyboard.nextLine();
addCompetitorInfo(mma);
}
setTitle("Bully's");
setLayout(new GridLayout(9,2,20,30));
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setVisible(true);
}
void addCompetitorInfo(MMACompetitors mma){
add (new JLabel (" "+ mma.getName()));
add (new JLabel(mma.getAverageString()));
}
}
和主類:
import java.io.IOException;
class ShowTeamFrame {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
new TeamMMA();
}
}
謝謝你的支持!我感謝每一個評論,我會接受所有建議!
你在MMAStatisticBullyTeam.txt中有什麼? –
就這一小塊文字:斯特凡 0.4 的Borko 0.6 總理 0.8 Arnauda 0.13 – user3747038