< class>的类型是netbeans中的错误错误 [英] The Type of <class> is erroneous error in netbeans

查看:96
本文介绍了< class>的类型是netbeans中的错误错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我正在编写的java程序定义了两个类,称它们为Class1和Class2。在Class1的构造函数的主体中,我调用了类2的构造函数。但是,我收到了编译错误

I have defined two classes for a java program I am writing, call them Class1 and Class2. In the body of the constructor for Class1, I call the constructor for class 2. However, I am getting the compile error

 "The type of Class1(JSONObject) is erroneous". 

我试过谷歌搜索此错误但无法在任何地方找到任何关于此确切错误的讨论,所以我想我将它发布到堆栈交换。

I tried googling this error but could not find any discussion of this exact error anywhere, so I thought I would post it to stack exchange.

有人可以解释一下这是什么类型的错误吗? class1和class2都非常简单:两者都只有一个构造函数方法,它在两种情况下都将JSONObject作为参数。唯一的导入是针对JSON。有什么建议吗?

Could someone please explain what type of error this is? Both class1 and class2 are very simple: both have only a constructor method, which takes a JSONObject as an argument in both cases. The only imports are for JSON. Any advice?

//class1 definition
public class Class1 {
       public Class1(JSONObject jObject){
           try{
           //parsing json and saving class variables
           } catch(Exception e)
           {
               System.out.println("Class1 JSON Exception: " + e.getMessage());
           }
       }
}


//constructor of Class2
Class1 user;

public Class2(JSONObject jObject){
    try{
    JSONObject userJSON = jObject.getJSONObject("user");
    user = new Class1(userJSON); //error occurrs here
    }
    catch(Exception e){
   System.out.println("Class2 JSON Exception: " + e.getMessage());

    }
}

}



<编辑:当我尝试运行代码时,即使出现此编译错误,我也会遇到以下运行时错误:

when I try to run the code even with this compile error, I get the following runtime error:

Exception in thread "main" java.lang.ExceptionInInitializerError
at bitcoin.thesis.Client.main(BTCJamClient.java:18)
Caused by: java.lang.RuntimeException: Uncompilable source code - Erroneous tree type:        
thesis.JSONArray
at thesis.Class3.<clinit>(Class3.java)
... 1 more
Java Result: 1

这里的Class3是另一个具有默认构造函数的类。 Client是主类,它接受http请求并将JSON对象传递给Class2构造函数。基本上,这是在Class1和Class2构造函数被调用之前代码执行的一部分。因此它不是由编译错误直接引起的,但我怀疑它们与我的编码环境中更常见的相同问题有关。

Class3 here is another class that has a default constructor. Client is the main class which takes the http request and passes the JSON object to Class2 constructor. Basically this is the part of the code execution before Class1 and Class2 constructors are even called. So it is not caused directly by the compile error, but I suspect they are related to the same problem that has do do more generally with my coding environment.

谢谢,
Paul

Thanks, Paul

推荐答案

我本来希望留下这个评论作为评论,但由于我没有声誉,我无法'吨。我意识到这也是一个非常晚的反应,但不知道你是否找到了答案。我在谷歌搜索答案时遇到了这个问题。

I would have preferred to leave this as a comment but as I do not have the reputation I couldn't. I realise this is also a very late response but don't know if you have found the answer or not. I came across this while googling for an answer myself.

我也相信这个错误与代码无关,而是由NetBeans创建的错误。我发现在一台机器上编译并运行了相同的代码并且在我第一次遇到错误的另一台机器上没有运行。

I also believe that this error is unrelated to the code but is rather an error created by NetBeans. I found the same code compiled and ran fine in NetBeans on one machine but not the on the other where I had first encountered the error.

我的解决方案是关闭NetBeans,清除NetBeans缓存并重新启动NetBeans。
我使用的是8.0版,我的缓存位置是:

The solution for me was to close NetBeans, clear the NetBeans cache and restart NetBeans. I was using version 8.0 and the location of the cache for me is:

〜/ .cache / netbeans / 8.0 /

~/.cache/netbeans/8.0/

我删除了文件夹中的所有内容,下次运行时一切正常。

I deleted everything in the folder and on the next run everything was fine.

对于旧版本,我认为缓存可能有所不同可以通过从帮助菜单打开关于窗口找到的位置。

For older versions I believe the cache may be in a different location which can be found by opening the about window from the help menu.

这篇关于&lt; class&gt;的类型是netbeans中的错误错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆