- - PR -
Eclipseの設定とプログラムのエラーメッセージについて
1
| 投稿者 | 投稿内容 |
|---|---|
|
投稿日時: 2004-04-23 10:27
Eclipseの設定とプログラムのエラーメッセージについて
WinXP Eclipse2.1.1を使用しております。 下記のようなプログラムにおいて、Eclipseがエラーメッセージを 表示します。(★の場所がそうです) 例えば、ExceptionTest2.javaにおいて、 exception.initCause(ex); の部分で、 メソッドinitCause(InterruptedException)は型IOExceptionで未意義 と、エラーメッセージが表示されています。 しかし、JavaAPIを確認したところ initCauseはThrowableから継承したメソッドなので何故エラーがでる のかがわかりません。 そこで、他のマシンのEclipseで下記のプログラムをチェックしてみると 全くエラーが表示されませんでした。よって、エラーはプログラムの問題では ないと思われます。私自身は、 二つのマシンにおける よって、Eclipseの設定の違いとか、jarが不足している等が 問題かと思っております。 どなたか、ご存知の方がいらっしゃいましたらご教授御願い致します。 --------TestException.java---------------------- public class TestException extends Exception { public TestException(String message){ super(message); } public TestException(String message, Throwable cause){ super(message, cause);//★コンストラクターException(String,Throwable)は未定義です。 } public TestException(Throwable cause){ super(cause);//★コンストラクターException(Throwable)は未定義です。 } } --------ExceptionTest1.java---------------------- public class ExceptionTest1 { public ExceptionTest1() { try { test(); } catch (TestException ex) { ex.printStackTrace(); } } private void test() throws TestException { try { throw new InterruptedException(); } catch (InterruptedException ex) { throw new TestException(ex); } } public static void main(String[] args) { new ExceptionTest1(); } } --------ExceptionTest2.java---------------------- import java.io.IOException; public class ExceptionTest2 { public ExceptionTest2(){ try { test(); } catch (IOException ex) { ex.printStackTrace(); } } private void test() throws IOException { try { throw new InterruptedException(); } catch (InterruptedException ex) { IOException exception = new IOException(); //★下記でEclipseにおいて、エラーがでている。 //initCauseはThrowableから継承したメソッドのはずなのにエラーがでる //メソッドinitCause(InterruptedException)は型IOExceptionで未意義 exception.initCause(ex); throw exception; } } public static void main(String[] args){ new ExceptionTest2(); } } --------ExceptionTest3.java---------------------- public class ExceptionTest3 { public ExceptionTest3(){ try { test(); } catch (TestException ex) { Throwable th = ex.getCause();//★メソッドgetCause()をTestException.javaに作成 th.printStackTrace(); } } private void test() throws TestException { try { throw new InterruptedException(); } catch (InterruptedException ex) { throw new TestException(ex); } } public static void main(String[] args){ new ExceptionTest3(); } } |
|
投稿日時: 2004-04-23 10:57
java.lang.Throwable#initCause(Throwable)は JDK 1.4 で追加されたメソッドです。おそらく複数の JDK がインストールされていて、Eclipse が使用しているのは JDK1.3 以前の JREシステムライブラリという設定になっているのではないかと思われます。
Eclipse 2.1 で日本語化してあれば、
|
1
