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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:13:32+00:00 2026-06-04T04:13:32+00:00

Here is the class where i get JSON objects. In this code I get

  • 0

Here is the class where i get JSON objects. In this code I get only one object and I don’t really know how to return from the method, there is a Protected Void method where it is a settext method called and there is where the only JSON object goes.

public class ConnectMySql extends Activity {

 TextView httpStuff;
 HttpClient client;
 JSONObject json;

 final static String URL = "http://79.114.48.119/RadarsMySql.php";

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    httpStuff = (TextView) findViewById(R.id.tvHttp);
    client = new DefaultHttpClient();
    new Read().execute("latitude");
}


public JSONObject lastTweet(String username) throws ClientProtocolException, IOException,JSONException{
    StringBuilder url = new StringBuilder(URL);
    url.append(username);


    HttpGet get = new HttpGet(url.toString());
    HttpResponse r = client.execute(get);
    int status = r.getStatusLine().getStatusCode();
    //if(status == 200){
        HttpEntity e = r.getEntity();

        String data = EntityUtils.toString(e);
        data = data.substring(data.indexOf("["));

        JSONArray timeline = new JSONArray(data);
        JSONObject last = timeline.getJSONObject(0);
        return last;

    //}else{ 
        //Toast.makeText(ConnectMySql.this, "error", Toast.LENGTH_LONG);
        //return null;

    //}
}

public class Read extends AsyncTask<String, Integer, String>{

    @Override
    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub
        try {
            json = lastTweet("");
            return json.getString(params[0]);
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void onPostExecute(String result) {
        // TODO Auto-generated method stub
        httpStuff.setText(result);
        int myNum = 0;

        try {
            myNum = Integer.parseInt(result);
            httpStuff.setText(myNum);
        } catch(NumberFormatException nfe) {
           System.out.println("Could not parse " + nfe);
        } 
    }

}

}

What I want to do is to have an array where i could store three kind of objects (exemple Latitude[1], Longitude [1], Description[1]; Latitude[2] etc… I would like the latitude and longitude to be as integers ). After this I will use a for loop to call a function with this 3 parameters. Could anyone help me or could give me some tips ?
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-04T04:13:33+00:00Added an answer on June 4, 2026 at 4:13 am

    Dont use AsyncTask, as it executes in background, and this is why it causes some problems for you.

    And when you have your twitter arser working, integrate it in a AsyncTask. Code below is not tested.

     public class ConnectMySql extends Activity {
    
     TextView httpStuff;
     HttpClient client;
     int i;
     JSONObject json;
    
     final static String URL = "http://localhost/RadarsMySql.php";
    
     @Override
     protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        httpStuff = (TextView) findViewById(R.id.tvHttp);
        client = new DefaultHttpClient();
        for(i=0;i<2;i++){
        new Read().execute("latitude");
    
            try {
                json = lastTweet("",i);
    
                String result = json.getString(params[i]);
    
             httpStuff.setText(result);
                int myNum = 0;
    
                try {
                    myNum = Integer.parseInt(result);
                    httpStuff.setText(myNum);
                } catch(NumberFormatException nfe) {
                   System.out.println("Could not parse " + nfe);
                } 
    
    
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
        }
    }
    
    
    public JSONObject lastTweet(String username,int i) throws ClientProtocolException, IOException,JSONException{
        StringBuilder url = new StringBuilder(URL);
        url.append(username);
    
    
        HttpGet get = new HttpGet(url.toString());
        HttpResponse r = client.execute(get);
        int status = r.getStatusLine().getStatusCode();
        //if(status == 200){
            HttpEntity e = r.getEntity();
    
            String data = EntityUtils.toString(e);
            data = data.substring(data.indexOf("["));
    
            JSONArray timeline = new JSONArray(data);
            JSONObject last = timeline.getJSONObject(i);
            return last;
    
        //}else{ 
            //Toast.makeText(ConnectMySql.this, "error", Toast.LENGTH_LONG);
            //return null;
    
        //}
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't get past this issue I am having. Here's a simple example: class
I found this code here class Usable; class Usable_lock { friend class Usable; private:
Given the code from here : class lazy_init { mutable std::once_flag flag; mutable std::unique_ptr<expensive_data>
My class objects are not getting converted into json, I think it returns object
I simply can not get Visual Studio 2005 to find the System.Configuration.ConfigurationManager class. Here
here is a class code : > [DataObjectAttribute] public class > Report { public
Im trying to parse an JSON response string to my class objects.. I can't
I am trying to read JSON objects using the QScriptValue class in Qt and
My AJAX-enabled WCF service returns JSON using this contract, [DataContract] public class JQGridContract {
I use this code to define my class in GAE Python: class Pair(db.Model): find

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.