Friday, January 4, 2013

common problem and solution on using datastore

problems and suitable solutions :

1- the import "com.google.appengine.api.datastore.key" cannot be resolved
this error is appeared during the runtime even Everything compiled just fine in the IDE.
Missing source files is a common stumbling block. What we've run into here is that the GWT compiler cannot find the source code for the com.google.appengine.Keyclass  
the first solution : is to create a Key class your self as described in this post
 http://fredsa.allen-sauer.com/2009/04/1st-look-at-app-engine-using-jdo.html.
the second solution: is to simply make the key field of "Long" type.

2- your data class (ChatMessage) is not default instantiable
Solution: make your data classes default instantiable(it must have a zero-argument constructor or no constructors at all), if your data class already has constructor with parameters so you just need to add another empty constructor.

3- ChatMessage has no custom serializer
so you can not serialize this object (send from client to server and vice versa)
solution: make your class implements Serializable  (java.io.Serializable)

4- List isn't serializable
more details about why it isn't serializable is in this post http://127.0.0.1:8888/MyFirstApp.html?gwt.codesvr=127.0.0.1:9997
Solution: so don't make the server's methods return List object, instead make it return ArrayList or vector or..
For this Problem where List isn't Serializable, you can find the answer on this link: http://stackoverflow.com/questions/4927227/why-doesnt-java-util-list-implement-serializable


last important notes: 

  • make sure that all fields in your data class is serializable.
  • some-times when you see a run-time error that doesn't make sense. Try cleaning your project and re-building it, if that doesn't solve it then try closing eclipse and open it back again, most of the time you will be good with this, but some-times you might even have to restart your computer. If all this attempts do not fix the problem then now for sure there is something wrong in your code. "ALL THIS IS ECLIPSE'S PROBLEM"
  • Sometimes an existing data might give you a problem when fetching from your datastore. To fix this remove your datastore(db) file. The Location is ../war/WEB-INF/appengine-generated/local_db.bin delete the local_db.bin file. 



Thanks to Sundus for providing his project, all these problems are solved in it,
you can download and import it from here
https://docs.google.com/open?id=0B1q8wbwjqNOwU2hGd2Vlc0tGVFE

3 comments:

  1. For the 4th Problem where List isn't Serializable, you can find the answer on this link: http://stackoverflow.com/questions/4927227/why-doesnt-java-util-list-implement-serializable

    ReplyDelete
  2. And one more thing, some-times when you see a run-time error that doesn't make sense. Try cleaning your project and re-building it, if that doesn't solve it then try closing eclipse and open it back again, most of the time you will be good with this, but some-times you might even have to restart your computer. If all this attempts do not fix the problem then now for sure there is something wrong in your code. "ALL THIS IS ECLIPSE'S PROBLEM"

    ReplyDelete
  3. Sometimes an existing data might give you a problem when fetching from your datastore. To fix this remove your datastore(db) file. The Location is ../war/WEB-INF/appengine-generated/local_db.bin delete the local_db.bin file.

    ReplyDelete