#要件
Javaアプレットでテキストを読み込みたいのですがエラーが出てしまいます。エラーの意味を調べたところ{}の数が合わないだとかスペルミスだとかあったんですけど、私には見つけられませんでした。
#ソース
Java
1import java.applet.Applet; 2 3/*<applet code="test1.class" width="400" height="400"></applet>*/ 4 5public class test1 extends Applet { 6 static ArrayList<Integer> a = new ArrayList<Integer>(); 7 static ArrayList<Integer> b = new ArrayList<Integer>(); 8 static ArrayList<Integer> c = new ArrayList<Integer>(); 9 public void init() { 10 try{ 11 File file = new File("C:\Users\○○\test.txt"); 12 if (checkBeforeReadfile(file)){ 13 BufferedReader br = new BufferedReader(new FileReader(file)); 14 String str; 15 while((str = br.readLine()) != null){ 16 List<Integer> ints = parse_line(str); 17 for (int i = 0; i < 3; i++) { 18 if(i == 0){ 19 a.add(ints.get(i)); 20 } 21 else if(i == 1){ 22 b.add(ints.get(i)); 23 } 24 else{ 25 c.add(ints.get(i)); 26 } 27 } 28 } 29 System.out.println(a+"\t"+b+"\t"+c); 30 br.close(); 31 } 32 else{ 33 System.out.println("ファイルが見つからないか開けません"); 34 } 35 } 36 catch(FileNotFoundException e){ 37 System.out.println(e); 38 } 39 catch(Exception e){ 40 System.out.println(e); 41 } 42 43 private static List<Integer> parse_line(String line) throws Exception { 44 List<Integer> ans = new ArrayList<Integer>(); 45 StringTokenizer st = new StringTokenizer(line, " "); 46 while (st.hasMoreElements()) { 47 String s = st.nextToken(); 48 try { 49 ans.add(Integer.parseInt(s)); 50 } 51 catch (Exception ex) { 52 throw new Exception("Bad Integer in " + "[" + line + "]. " + ex.getMessage()); 53 } 54 } 55 return ans; 56 } 57 58 private static boolean checkBeforeReadfile(File file){ 59 if (file.exists()){ 60 if (file.isFile() && file.canRead()){ 61 return true; 62 } 63 } 64 return false; 65 } 66 } 67 public void start() { 68 System.out.println("start()ですぅ~"); 69 } 70 public void stop() { 71 System.out.println("stop()ですぅ~"); 72 } 73 public void destroy() { 74 System.out.println("destoroy()ですぅ~"); 75 } 76}
#エラーメッセージ
test1.java:43: エラー: 式の開始が不正です
private static List<Integer> parse_line(String line) throws Exception {
^
test1.java:67: エラー: class、interfaceまたはenumがありません
public void start() {
^
test1.java:69: エラー: class、interfaceまたはenumがありません
}
^
test1.java:70: エラー: class、interfaceまたはenumがありません
public void stop() {
^
test1.java:72: エラー: class、interfaceまたはenumがありません
}
^
test1.java:73: エラー: class、interfaceまたはenumがありません
public void destroy() {
^
test1.java:75: エラー: class、interfaceまたはenumがありません
}
^
エラー7個
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/30 23:16
2017/12/31 09:51