简体   繁体   English

Java安装不正确吗? 线程“ main”中的异常java.lang.NoSuchMethodError

[英]Is Java not installed correctly? Exception in thread “main” java.lang.NoSuchMethodError

Recently when I write any code and compile it, then try to run it I get this exception: 最近,当我编写任何代码并进行编译,然后尝试运行它时,出现此异常:

Exception in thread "main" java.lang.NoSuchMethodError 线程“主”中的异常java.lang.NoSuchMethodError

At first I thought there is something wrong in my code, but I couldn't find anything wrong with it. 起初我以为我的代码有问题,但是我找不到任何错误。 When trying to run a HelloWorld example that had worked before, if works, but if I copy the exact same code into a file HelloWorld2 I get this exception again. 尝试运行以前曾运行过的HelloWorld示例时,如果可以运行,但是如果我将完全相同的代码复制到文件HelloWorld2 ,则会再次出现此异常。

The code is identical but when I used javap to decompile both class files I found a difference. 代码是相同的,但是当我使用javap反编译两个类文件时,我发现有所不同。 In HelloWorld (the original file) HelloWorld (原始文件)

"public static void main(java.lang.String[])";

and in HelloWorld2 (the new one) HelloWorld2 (新的)

"public static void main(String[])";

without java.lang. 没有java.lang. .

I recompiled the old HelloWorld with javac and now when I try to run it it doesn't work and I get the same exception. 我用javac重新编译了旧的HelloWorld ,现在尝试运行它时,它不起作用,并且出现了相同的异常。 None of my old code now works if I recompile it. 现在,如果我重新编译它,所有旧代码都无法正常工作。

I've searched everywhere but can't find a solution to this problem - any idea what is going on here? 我到处搜索,但找不到解决该问题的方法-知道这里发生了什么吗?

You may get this if you have your own class called String (without a package) in your classpath. 如果您在类路径中有自己的名为String的类(不带包装),则可能会得到此信息。 It sounds like that's what happened. 听起来就是那样。 Here's a way to try to reproduce this - compile it and run it, and see if it looks the same: 这是尝试重现此方法的一种方法-编译并运行它,看看它看起来是否相同:

class String {} 

public class Test {
    public static void main(String[] args) {
    }    
}

Once you've got the compiled String.class file in your file system in an awkward place, that will be used by default even if you only compile the Test class above... 一旦将文件系统中的String.class编译文件放在一个笨拙的位置,即使您仅编译上面的Test类,也将默认使用该文件。

Basically, see if you can find a file called String.class somewhere. 基本上,看看是否可以在某个地方找到一个名为String.class的文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “线程“ main”中的异常java.lang.NoSuchMethodError” - “Exception in thread ”main“ java.lang.NoSuchMethodError ” Java错误:线程“main”中的异常java.lang.NoSuchMethodError:main - Java error: Exception in thread “main” java.lang.NoSuchMethodError: main 线程“ main”中的异常java.lang.NoSuchMethodError:main-如何解决? - Exception in thread “main” java.lang.NoSuchMethodError: main - how to fix it? 不断在线程“ main”中获取异常java.lang.NoSuchMethodError:main? - keep getting Exception in thread “main” java.lang.NoSuchMethodError: main? 线程“main”中的异常 java.lang.NoSuchMethodError: main - Exception in thread "main" java.lang.NoSuchMethodError: main 为什么线程“ main”中的异常java.lang.NoSuchMethodError:main? - Why Exception in thread “main” java.lang.NoSuchMethodError: main? 线程“ main”中的异常java.lang.NoSuchMethodError:main //有什么问题? - Exception in thread “main” java.lang.NoSuchMethodError: main // What is wrong? 线程“ main”中的Javap异常java.lang.NoSuchMethodError - Javap Exception in thread “main” java.lang.NoSuchMethodError AWS Textract:线程“main”中的异常 java.lang.NoSuchMethodError - AWS Textract: Exception in thread "main" java.lang.NoSuchMethodError 线程“ main”中的JNI GetMethodID异常java.lang.NoSuchMethodError: <method> - JNI GetMethodID Exception in thread “main” java.lang.NoSuchMethodError: <method>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM