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.
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());
}
}
}
EDIT: 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 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.
Thanks, Paul
Compile On Save- BrajuserJSONand where did you define it? - Vimal Bera