我收到此错误消息:
Main method not found in class User, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
我的文件有主要但是...... 以下是我的代码。
import org.json.simple.JSONObject;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.json.simple.JSONArray;
import org.json.simple.parser.ParseException;
import org.json.simple.parser.JSONParser;
public class User {
public static void main(String [] args) {
JSONParser parser = new JSONParser();
try {
Object obj = parser.parse(new FileReader("users.json"));
System.out.println("file exists.");
JSONArray jsonArray = (JSONArray) obj;
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
//System.out.println(jsonObject);
int id = i;
String first_name = (String) jsonObject.get("first_name");
System.out.println(first_name);
String last_name = (String) jsonObject.get("last_name");
System.out.println(last_name);
String email = (String) jsonObject.get("email");
System.out.println(email);
String gender = (String) jsonObject.get("gender");
System.out.println(gender);
String interested = (String) jsonObject.get("interested");
System.out.println(interested);
double longitude = (double) jsonObject.get("longitude");
System.out.println(longitude);
double latitude = (double) jsonObject.get("latitude");
System.out.println(latitude);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
}
这只是将所有json文件解析为java的基本代码,因此我可以基于此构建图形。但我收到此错误消息(我已经google了,发现了类似的错误消息),即使我有主要方法。 我该怎么做才能解决这个问题?