java.lang.RuntimeException:未能调用没有参数的 public com.example.syncapp.MessageBase()
2022-09-01 22:50:07
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println(request.getParameter("msg").toString());
String data = request.getParameter("msg").toString();
Gson gson = new Gson();
MessageBase msggg = gson.fromJson(data, MessageBase.class);
//System.out.println(msggg.Id + msggg.MessageText);
}
public abstract class MessageBase implements Serializable {
public int Id;
public String MessageText;
public Date ReceiveDate;
}
public class SyncSmsMessage extends MessageBase {
public String SenderNum;
}
代码一直有效,直到 .我得到这个例外:MessageBase msggg=gson.fromJson(data, MessageBase.class);
java.lang.RuntimeException: Failed to invoke public com.example.syncapp.MessageBase() with no args
at com.google.gson.internal.ConstructorConstructor$2.construct(ConstructorConstructor.java:94)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:162)
at com.google.gson.Gson.fromJson(Gson.java:795)
at com.google.gson.Gson.fromJson(Gson.java:761)
at com.google.gson.Gson.fromJson(Gson.java:710)
at com.google.gson.Gson.fromJson(Gson.java:682)
at AndroidServlet.doPost(AndroidServlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
我需要做什么?我把.jar放在lib文件夹中,我认为tomcat加载.jar好。