Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8740423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:07:43+00:00 2026-06-13T11:07:43+00:00

I’m able to retrieve a data from my php mysql to my android but

  • 0

I’m able to retrieve a data from my php mysql to my android but it seems their is a problem with my code when I’m trying to put it to my List View.

Here’s my Activity Codes

public class View extends Activity{

     // Progress Dialog


    // Creating JSON Parser object
    JSONParser jParser = new JSONParser();

    ArrayList<HashMap<String, String>> productsList;

    // url to get all products list
    private static String url_all_products = "http://atlantis-us.com/viewFile.php";

    // JSON Node names
    private static final String TAG_NAME = "name";
    ListView lv;
    // products JSONArray
    JSONArray products = null;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.all_products);


        // Get listview
        lv = (ListView) findViewById(R.id.list);

        // Hashmap for ListView
        productsList = new ArrayList<HashMap<String, String>>();

        new LoadAllProducts().execute();


    }

    class LoadAllProducts extends AsyncTask<String, String, String> {

        @Override
        protected String doInBackground(String... arg0) {
            // TODO Auto-generated method stub
             // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();

            JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
            Log.d("All Products: ", json.toString());
            ListAdapter adapter = new SimpleAdapter(
                    View.this, productsList,
                    R.layout.list_item, new String[] {
                            TAG_NAME},
                    new int[] {R.id.name });
            // updating listview
            lv.setAdapter(adapter);

            return null;

        }
    }

}

and Here’s my JSONParser Class

public class JSONParser {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    // constructor
    public JSONParser() {

    }

    // function get json from url
    // by making HTTP POST or GET method
    public JSONObject makeHttpRequest(String url, String method,
            List<NameValuePair> params) {

        // Making HTTP request
        try {

            // check for request method
            if(method == "POST"){
                // request method is POST
                // defaultHttpClient
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();

            }else if(method == "GET"){
                // request method is GET
                DefaultHttpClient httpClient = new DefaultHttpClient();
                String paramString = URLEncodedUtils.format(params, "utf-8");
                url += "?" + paramString;
                HttpGet httpGet = new HttpGet(url);

                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }           

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;

    }
}

this is what log cat says

10-26 14:57:53.673: I/Choreographer(1391): Skipped 61 frames!  The application may be doing too much work on its main thread.
10-26 14:57:54.653: D/All Products:(1391): {"products":[{"name":"Ghalia"},{"name":"yuan"},{"name":"kevin"},{"name":"kevin"},{"name":"kevin"},{"name":"Ghalia"},{"name":"Ghalia"},{"name":"dbgg"},{"name":"Ghalia"},{"name":"Ghalia"},{"name":"test"}]}
10-26 14:57:54.663: W/dalvikvm(1391): threadid=11: thread exiting with uncaught exception (group=0x40a13300)
10-26 14:57:54.684: E/AndroidRuntime(1391): FATAL EXCEPTION: AsyncTask #1
10-26 14:57:54.684: E/AndroidRuntime(1391): java.lang.RuntimeException: An error occured while executing doInBackground()
10-26 14:57:54.684: E/AndroidRuntime(1391):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at java.lang.Thread.run(Thread.java:856)
10-26 14:57:54.684: E/AndroidRuntime(1391): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
10-26 14:57:54.684: E/AndroidRuntime(1391):     at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4607)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:835)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at android.view.View.requestLayout(View.java:15129)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at android.view.View.requestLayout(View.java:15129)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at android.view.View.requestLayout(View.java:15129)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at android.view.View.requestLayout(View.java:15129)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at android.view.View.requestLayout(View.java:15129)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at android.widget.AbsListView.requestLayout(AbsListView.java:1928)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at android.widget.ListView.setAdapter(ListView.java:488)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at com.example.mysql.View$LoadAllProducts.doInBackground(View.java:74)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at com.example.mysql.View$LoadAllProducts.doInBackground(View.java:1)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-26 14:57:54.684: E/AndroidRuntime(1391):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-26 14:57:54.684: E/AndroidRuntime(1391):     ... 5 more

is there anyone have thoughts whats causing the error?
any suggestion will be appreciated.
thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:07:43+00:00Added an answer on June 13, 2026 at 11:07 am

    Inside doInBackground(), you can’t perform updating operation for Any View directly.

    So you are doing mistake here in doInBackground():

     ListAdapter adapter = new SimpleAdapter(
                        View.this, productsList,
                        R.layout.list_item, new String[] {
                                TAG_NAME},
                        new int[] {R.id.name });
                // updating listview
                lv.setAdapter(adapter);
    

    So write this code inside onPostExecute().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I want to construct a data frame in an Rcpp function, but when I
I'm trying to create an if statement in PHP that prevents a single post
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.