Hallo,
ich hoffe das ist die richtige Kategorie für mein Problem also ich will ganz gerne Notizen auf der App Engine speichern.
Ich hab mir dazu das "Tutorial" aus dem Buch Android-Apps entwickeln angesehen leider bekomme ich immer ein fehler
hier die Anwendung:
ZitatAlles anzeigenpackage de.freeemoser.lazerussaveserver;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.*;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.FetchOptions;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.Query;
@SuppressWarnings("serial")
public class LazerusSaveServerServlet extends HttpServlet {
private ServletRequest req;
String title = req.getParameter("title");
String body = req.getParameter("body");
String user = req.getParameter("user");
private ServletResponse resp;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
System.out.println("tes");
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
if (title != null && body != null && user != null) {
saveNote(user, title, body);
}
returnNote();
}
private void returnNote() throws IOException {
System.out.println("tes");
com.google.appengine.api.datastore.DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
com.google.appengine.api.datastore.Key TitleKey = KeyFactory.createKey("title", title);
Query query = new Query("SaveNote", TitleKey);
query.addSort("User", Query.SortDirection.DESCENDING);
List<Entity> SaveNote = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(10000));
for(Entity e: SaveNote) {
resp.getWriter().println(e.getProperty("title") + "," + e.getProperty("body"));
}
}
private void saveNote(String user, String title, String body) {
com.google.appengine.api.datastore.DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
com.google.appengine.api.datastore.Key TitleKey = KeyFactory.createKey("title", title);
com.google.appengine.api.datastore.Entity Note = new Entity ("Note", TitleKey);
Note.setProperty("user", user);
Note.setProperty("body", body);
datastore.put(Note);
}
}
und Hier der Fehler:
ZitatAlles anzeigenHTTP ERROR 500
Problem accessing /lazerussaveserver. Reason: INTERNAL_SERVER_ERROR
Caused by:
java.lang.NullPointerException
at de.freeemoser.lazerussaveserver.LazerusSaveServerServlet.<init>(LazerusSaveServerServlet.java:20)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:428)
at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:60)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:78)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:369)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
weiß einer vlt woran das liegt? Danke fürs Lesen und danke für die Hilfe