Java 无法编译的源代码 - 错误的符号类型:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35114025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 16:19:41  来源:igfitidea点击:

Uncompilable source code - Erroneous sym type:

java

提问by Dissanayake

There was error occurred in Line 14.

第 14 行出现错误。

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type:

线程“main”中的异常 java.lang.RuntimeException:无法编译的源代码 - 错误的符号类型:

Hard to find solution.

很难找到解决办法。

package example;

public class Num
{
    public static void main(String [] args) 
    {
    String s = "42";
        try 
        {
            s = s.concat(".5"); 
            double d = Double.parseDouble(s);
            s = Double.toString(d);
            int x = (int) Math.ceil(Double.valueOf(s).doubleValue()); //Line 14
            System.out.println(x);
        }
        catch (NumberFormatException e) 
        {
            System.out.println("Wrong Number");
        }
    }
}

采纳答案by sinclair

The code you provided runs fine on my computer.

您提供的代码在我的电脑上运行良好。

I'm guessing you are using Netbeans and may be affected by a bug. Try this:

我猜您正在使用 Netbeans,并且可能会受到错误的影响。尝试这个:

Open the project properties, select the Build-Compiling, uncheck "Compile on save" and rerun the application. This will make sure all your source code becomes recompiled before running it.

打开项目属性,选择 Build-Compiling,取消选中“Compile on save”并重新运行应用程序。这将确保您的所有源代码在运行之前都被重新编译。

Link: https://forums.netbeans.org/topic43241.html

链接:https: //forums.netbeans.org/topic43241.html

回答by Roshana Pitigala

This is a common issue which I get while working. What I do is clean and build the project. It solves the problem.

这是我在工作时遇到的一个常见问题。我所做的是清理和构建项目。它解决了这个问题。

Right Click on the project name >> Clean and build

右键单击项目名称>> Clean and build

回答by Abdo

I got this error message because I copied and pasted code without including the package name. I added the package name and it was fixed.

我收到此错误消息是因为我复制和粘贴的代码不包含包名称。我添加了包名称并已修复。

回答by Shah Harsh

in my case

就我而言

i have solved using import with package name and class name

我已经解决了使用带有包名和类名的导入

like this import package.class1;

像这样 import package.class1;

回答by Hemanth Kollipara

Even I encountered the same problem then I fixed it by doing the below Just create another main class file Then add new class file to the source project file It will work definitely

即使我遇到了同样的问题,然后我通过执行以下操作来修复它只需创建另一个主类文件然后将新类文件添加到源项目文件中它肯定会起作用

回答by Dave

I received this error after I'd changed the type of a function parameter and it was the calling page that was in error - but I didn't see this until a magical Clean and Buildpointed me to the actual issue!

我在更改函数参数的类型后收到此错误,并且是调用页面出错了 - 但直到神奇的Clean and Build 将我指向实际问题时我才看到这一点!

回答by Milad Tazikeh

Please uncheck "Compile on save"

请取消选中“保存时编译”

attention to the pic

注意图片