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

+6
source share
7 answers

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.

+31
source

Make sure you enter the correct package names in your classes.

+3
source

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!

+2
source

I had the same problem on netbeans 8.0 . The following trick should fix this:

Right-click on the project -> properties -> build -> compiling ==> uncheck "compile on save", then click "OK"

+1
source

I ran into this problem. I solved this by adding all the dependent jars to the project / file

0
source

Lubricate the answer to remove the contents of the netbeans cache. I am using Netbeans 8.1 on MacOS Sierra.

Removed everything in the "/Users//Library/Caches/NetBeans/8.1/" section

0
source

I have the same problem and fixed it using a delayed response, since I am using Windows 10, so here is the folder with the cache folder:

C: \ Users \ username \ AppData \ Local \ NetBeans \ Cache \ 8.1

AppData is a hidden folder.

0
source

All Articles