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 をうまくロードすると思います。