Tyler
Tyler

Reputation: 19848

Weird IOException pre 1.6 error on 1.6 environment

I am trying to pass e of type IOException as the cause in a new IOException as shown below.

try {
    //stuff
}
catch (IOException e) {
    throw new IOException("Some Message", e);
}

This gives me the error below:

The constructor IOException(String, IOException) is undefined

However, in 1.6, IOException(String, Throwable) is implemented as a constructor for this class.

It's like I'm in Java 1.5, even though everything in my project properties says 1.6! I don't even have a 1.5 JDK installed on my hard drive!

Upvotes: 0

Views: 428

Answers (3)

Tyler
Tyler

Reputation: 19848

I was referencing the incorrect android.jar in my project setup.

Also note that this constructor was introduced in the Android API in API Level 9. If you're using anything below that, then you won't be able to use it. – Joachim Sauer Aug 4 at 14:44

Upvotes: 0

Jörn Horstmann
Jörn Horstmann

Reputation: 34024

The Java version on Androind only implements 1.5 features. You should be able to use the initCause method like this:

IOException e2 = new IOException("Some message");
e2.initCause(e);
throw e2;

Upvotes: 2

Eric Levine
Eric Levine

Reputation: 13564

Try doing this inside your catch instead:

throw new IOException("Some Message", e.getCause());

Upvotes: 0

Related Questions