java - Error fetching entity by Entity Id from Google App Engine backend for Android app -
I am using Google App Engine as a backend for my Android app. I am able to incorporate entities into the datastore using the method (when I make a closing point for my note class)
/ ** * This app engine is a new unit If the unit is already present in the * datastore, an exception is inserted. * It uses the HTTP posting method Note the unit inserting the * * Ultimate. * @Returned Unit * / @APImath (Name = "Insert Note") Enter Public Note Note (note note) {EntityManager mgr = getEntityManager (); {Try (note (note)} {New EntityExistsException ("Object already exists"); } Mgr.persist (note); } Finally {mgr.close (); } Return note; }
To do this using the method from my Android app and to insert one unit, I'll call it my AsyncTask class
{Note Note = New Note (); String descrptn = descriptionTF.getText () ToString (); String Email = emailTF.getText (). ToString (); String note id = new date (). ToString (); Note.setDescription (descrptn); Note.setId (noteID); Note.setEmailAddress (email); Note Result = endpoint.insert Note (note) .execute (); } Hold (IOException e) {e.printStackTrace (); }
Unless I try to get the unit from datastore, it is all sunlight and rainbow. I receive a Fatal exception ... ... due to Java.lang.NullPointerException: The expected parameter ID should be specified
This is a unit (also generated automatically) Method of calling when trying to retrieve
/ ** * This method becomes the primary key ID unit using the HTTP GET method * * @The Ultimate ID Java Bin Primary key of * @Returning unit with primary key ID * / @ApiMethod (name = "getNote") public Protein getNote (@ Named ( "id") String id) {EntityManager mgr = getEntityManager (); Note note = null; Try {note = mf.find (note.class, id); } Finally {mgr.close (); } Return note; }
And this is what is trying on my Android activity
try {note: new note = new note (); String note id = newnot.getit (); Note: newResult = endpoint.getNote (note ID) .execute (); String descrptn = newResult.getDescription (); String Email = New Reset. Email Address (); DescriptionTV.setText (descrptn); EmailTV.setText (email); } Hold (IOException e) {e.printStackTrace (); } Return (Long) 0; }
Can anyone help me?
In your Android activity, I see the following code:
NoteNew Note = New Note (); String note id = newnot.getit (); Note: newResult = endpoint.getNote (note ID) .execute ();
If you see, then you are making an example of the note () class in the first line, it still means that the notes contain other features of the class, and in which the Id < / Code> are included, are zero. So in fact on your second line, you are assigning
null
to notidi
and it is being passed by the endpoint getNote
method. Therefore the server becomes a null for the side ID and therefore throws an exception.
In your Android code, you can show a list of notes in some ListActivity
and then when you are selecting a note, you can select selectedItem
You will be able to get the ID from Therefore you should pass this value to get the details from the server endpoint implementation instead.
Hope this clarifies things.
Comments
Post a Comment