Type <class> - error in netbeans
I have defined two classes for the java program I am writing, call them Class1 and Class2. In the constructor body for Class1, I call the constructor for class 2. However, I get a compilation error
"The type of Class1(JSONObject) is erroneous". I tried using this error, but could not find any discussion of this exact error anywhere, so I thought that I would send it to the exchange stack.
Can someone explain what this error is? Both classes 1 and class2 are very simple: both have only a constructor method, which in both cases accepts JSONObject. The only import for JSON. Any tips?
//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()); } } } EDIT: when I try to run the code even with this compilation 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 is another class with a default constructor. The client is the main class that accepts an HTTP request and passes a JSON object to the Class2 constructor. This is basically part of the code execution before the Class1 and Class2 constructors are even called. Thus, this is not caused by a compilation error, but I suspect that they are related to the same problem, which is more common with my coding environment.
Thanks Paul
I would prefer to leave this as a comment, but since I have no reputation, I could not. I understand that this is also a very late answer, but I donβt know if you found the answer or not. I came across this, although I myself was looking for an answer.
I also believe that this error is not related to code, but rather is an error created by NetBeans. I found that the same code compiled and worked fine in NetBeans on one computer, but not on another, where I first encountered this error.
The solution for me was to close NetBeans, clear the NetBeans cache, and restart NetBeans. I used version 8.0, and the cache location for me is:
~ / .cache / NetBeans / 8.0 /
I deleted everything in the folder, and the next time everything was in order.
For older versions, I believe that the cache may be in a different place, which can be found by opening the about window from the help menu.
I had the same problem and the solution was very simple in my case.
Happening:
I am copying / pasting some classes from another project into the project package in which I work.
Some of them had an old package declaration, and the compiler did not complain (for its reasons).
When I used the type return method of one of the "wrong packed" classes, this error appeared.
(Type of error)
Decision
To solve the problem, I changed the package declaration as correct!