简体   繁体   中英

eclipse BigInteger compilation issue

I am using Java 1.6.0_45. I have a simple java code that uses BigInteger. It runs fine when I run from command line (javac and then java )

Now, when I run the same code from eclipse, I get a compilation error! I printed the version of java in both the runs and the java run time version is the same.

Here is the code:

import java.math.*;

public class BigInteger2 {
     public static void main(String[] args) {
          System.out.println(System.getProperty("java.version"));
          BigInteger b1 = new BigInteger("3");
     }
}

The error (only in Eclipse) that I get is the following :

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
The constructor BigInteger(String) is undefined at BigInteger2.main(BigInteger2.java:10)

It is basically complaining about new BigInteger("3")

What am I missing here? Some configuration setting in eclipse? Why does it run fine when I compile and invoke from command line and why doesnt it run in eclipse? please suggest. Thanks!!

尝试清理并构建项目,然后运行编

What is the JDK/JRE you have set up in the Preferences under Java->Installed JRE's? Is it the same JDK you referring to in your question? Have you probably set the -vm parameter in your eclipse.ini to an older JDK? You may provide the -vm Parameter there to ensure that the right JDK is used to start eclipse itself. [ http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fruntime-options.html ]

Go to your project -> right click -> Properties -> java Build Path -> Libraries and check your version of JRE System Library

BigInteger is present since JDK 1.1, but am not sure about the String constructor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM