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 9074557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:39:52+00:00 2026-06-16T18:39:52+00:00

I’m Junior Android Developer and I’m using JSON to get data from PHP file

  • 0

I’m Junior Android Developer and I’m using JSON to get data from PHP file on webserver that gets data from MySql database

This is my code

public void onlinegetbooks() {

    try {

        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

        nameValuePairs.add(new BasicNameValuePair("user",userid));

        HttpClient httpclient = new DefaultHttpClient(); 

        try{
            HttpPost httppost = new HttpPost("http://url/mybooks.php");

            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();

        }catch(Exception e){
            Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
        }
        //buffered reader
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 80);
            sb = new StringBuilder();
            sb.append(reader.readLine() + "\n");
            String line = "0";
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            resultt = sb.toString();

            System.out.println("in onlinegetbooks, resultt: "+resultt); 
            System.out.println("onlinegetbooks StringBuilder: "+sb);

        }catch(Exception e){
            Toast.makeText(getApplicationContext(), "invalid", Toast.LENGTH_LONG).show();
        }

                            resultt = resultt.substring(1);
            jArray = new JSONArray(resultt);
        System.out.println("in onlinegetbooks jArray.length(): "+jArray.length());

        try{

            JSONObject json_data = null;

            for (int i = 0; i < jArray.length(); i++) {
                json_data = jArray.getJSONObject(i); 

                targetcover=json_data.getString("bo_cover_img");
                targetbname = json_data.getString("bo_name"); 
                targetbpath = json_data.getString("bo_path"); 
                targetbpartion=json_data.getString("bo_bg_id"); 
                targetauthname=json_data.getString("au_name");
                targetbokid=json_data.getString("bo_id");
                targetbokabout=json_data.getString("bo_about");

                coverr.add(targetcover); 
                bnamee.add(targetbname);
                bpathh.add(targetbpath );
                bpartionnn.add(targetbpartion);
                authnamee.add(targetauthname);
                bokiddd.add(targetbokid);
                bokabouttt.add(targetbokabout);

            }

            fflage=true;

    }catch(JSONException e){
            Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
        }   
    } catch (ParseException e) {
        Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
    }  
    catch (Exception e) {
        Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
    }       

}

and I call this Function in the following code

private class LoadData extends AsyncTask<Void, Void, Void> { 
    private ProgressDialog progressDialog;  

    @Override

    protected void onPreExecute() {

        CharSequence contentTitle = getString(R.string.loginning);
        this.progressDialog = ProgressDialog.show(loginActivity.this,"",contentTitle); 

    }

    @Override
    protected void onPostExecute(final Void unused) {  
        this.progressDialog.dismiss();  

        if(fflage){

        Intent myBooks = new Intent(getApplicationContext(),TabsOFBooks.class);

        myBooks.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(myBooks);
        finish(); 

        } else {
            Toast.makeText(getApplicationContext(),R.string.noinfo, Toast.LENGTH_LONG).show();
        }

    }


    @Override
    protected Void doInBackground(Void... params) {

        try{
            bk.deletetable();
            recb.deletetable();
            mosb.deletetable();
            frboks.deletetable();
            ggp.deletetable();

        addusers();
        onlinegetbooks();
        addmybooks();

        onlinerecentbooks();

        fflage=true;
        }
        catch (Exception e) {
            System.out.println("No Information");

        }

        return null;

    }

}

My Problem is in the resultt = sb.toString();

When the resultt is Null in not continue the other lines in the code and not prints this line

System.out.println("in onlinegetbooks jArray.length(): "+jArray.length());
  • 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-16T18:39:53+00:00Added an answer on June 16, 2026 at 6:39 pm

    Currently you are trying to Show Toast messages from doInBackground which is not possible because we are not able to access UI elemnts from doInBackground method of AsyncTask . your can change your AsyncTask class as for updating UI when doInBackground execution complete

    private class LoadData extends AsyncTask<Void, Void, Void> { 
        private ProgressDialog progressDialog;  
    
        @Override
    
        protected void onPreExecute() {
    
    
    
        }
    
    
    
    
        @Override
        protected Void doInBackground(Void... params) {
    
            // call your methods here for getting data from server
    
            return null;
    
        }
    
         @Override
        protected void onPostExecute(final Void unused) {  
            this.progressDialog.dismiss();  
              // show toast messages or UI date UI here 
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jsonparser to parse data and images obtained from json response. When
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using an ASP request returning a XML file containing some latin characters. By
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.