aspose file tools*
The moose likes Android and the fly likes Failed to load details from database using java and php Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Failed to load details from database using java and php" Watch "Failed to load details from database using java and php" New topic
Author

Failed to load details from database using java and php

Chin Ginger
Greenhorn

Joined: Mar 31, 2014
Posts: 6
I have developed an Android apps which includes a function of writing memo.
After user clicks on the view memo, there is a list of memo name. User can click on the specific memo to display the details in edit form.
I have tested the php code by using the browser, it returns the correct memo details.
But unfortunately, after user clicks on the selected memo, the apps has stopped working.

here is the java code:


here is the log file:



here is the php code:

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
Welcome to JavaRanch.

Either turn StrictMode off (a bad idea, but quick to implement) or -much better- move network access off the event thread into a background thread. I frequently use AsyncTask for that.


Ping & DNS - my free Android networking tools app
Chin Ginger
Greenhorn

Joined: Mar 31, 2014
Posts: 6
Ulf Dittmer wrote:Welcome to JavaRanch.

Either turn StrictMode off (a bad idea, but quick to implement) or -much better- move network access off the event thread into a background thread. I frequently use AsyncTask for that.


Hi, do you have any idea to move the codes into PublishProgress and onProgressUpdate?
I have tried that but not really what parameters should be put in the onProgressUpdate.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
Why are you running the thread with "runOnUiThread"? That negates the effect of using AsyncTask. You should store the result of the JSON call, and then use it in onPostExecute.
Chin Ginger
Greenhorn

Joined: Mar 31, 2014
Posts: 6
Ulf Dittmer wrote:Why are you running the thread with "runOnUiThread"? That negates the effect of using AsyncTask. You should store the result of the JSON call, and then use it in onPostExecute.


I have tried to return json in the doInBackground but it getting the error of "json cannot be resolved to a variable"
Can give me more clues about this? I am a newbie and willing to learn more.
Thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
I have tried to return json in the doInBackground but it getting the error of "json cannot be resolved to a variable"
Can give me more clues about this?

If you're asking about specific code, post that code, or rather, the relevant excerpts of it; otherwise we don't really know what you're talking about
Chin Ginger
Greenhorn

Joined: Mar 31, 2014
Posts: 6
Ulf Dittmer wrote:Why are you running the thread with "runOnUiThread"? That negates the effect of using AsyncTask. You should store the result of the JSON call, and then use it in onPostExecute.


sorry for my poor english..
but if based on your statement above, how to modify my codes to make it work?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
Start by removing all the Runnable stuff. Then move the processing of the JSON - as opposed to the retrieval of it- into the onPostExecute method.
Chin Ginger
Greenhorn

Joined: Mar 31, 2014
Posts: 6
Ulf Dittmer wrote:Start by removing all the Runnable stuff. Then move the processing of the JSON - as opposed to the retrieval of it- into the onPostExecute method.


thanks I have solved the problem.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
Good. You should move lines 20 and 21 into onPostExecute as well. There is no need to have references to those two anywhere else.

And, of course, you should do proper error handling in case the JSON can't be retrieved, or doesn't contain the right results. Blindly accessing elements of the list -as the code does now- will come back to hurt you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Failed to load details from database using java and php