0

I am trying the try with resource statement:

    try(ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(defaultFile)))
    {
        ;
    }
    catch(IOException e)
    {
        ;
    }

But I get syntax error, which makes me think that I need the newest version of Java. So I have downloaded the latest Jre and Jdk from Oracle site, but I don't know how to effectively substitute the new Jre and Jdk with the older ones. I have tried from eclipse windows->preferences->installed JREs, the is the option "search".But If I try searching in the directory where I have Jre and Jdk files, it says that no valid Jre was found. How to effectively update Jre and Jdk? PS:I am on ubuntu 10.10

4

4 回答 4

2

First, make sure you are using the latest release of Eclipse (Indigo SR2, aka 3.7.2); full Java 7 support wasn't available until Eclipse 3.7.1

Now, on the Installed JREs preferences page, are you using the Add... button to point to the root of your JDK installation? Describe the steps you have taken to get the "no valid JRE found" message.

于 2012-04-04T21:37:29.107 回答
1

If you're trying to use the newtry-with-resources statement of Java 7 you should first of all look at the correct syntax here or doing some other web search. This link have some nice examples as well.

This being said, even if I'm not super familiar with Ubuntu 10.10, the following instruction should do the job: Installing Java 7 in Ubuntu.

Hope this helps!

于 2012-04-04T20:37:31.120 回答
-1

I think "upgrading Xyz" is not a programming question but an administration question. Especially the Ubuntu companion site https://askubuntu.com/ is a better place for this question.

A quick look there turned up this may helpful post:

https://askubuntu.com/questions/89556/getting-java-working-again-in-10-10-or-force-newest-version-of-openjdk

于 2012-04-04T20:42:02.573 回答
-2

your JDK and JRE are ok. Your code has an error. It should look like this:

try
{
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(defaultFile));
}
catch (IOException e)
{
    e.printStackTrace();
}
于 2012-04-04T20:30:14.017 回答