• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Failed to load details from database using java and php

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Chin Ginger
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic