Results 1 to 2 of 2
  1. #1
    fresh83 is offline Member
    Join Date
    Dec 2009
    Posts
    55
    Rep Power
    0

    Default Java/Android JSON Problem

    Alright , so I followed a tutorial line for line , I received no errors when I compiled , yet when I run it load text flickers for a second and then ....nothing.


    Ive spent about a half hour trying to figure it out and im stumped , heres my code & a image of my logcat after running it w. the errors i receive and YES.. Ive checked my permissions and allowed internet in the manifest :

    http://imageshack.us/f/695/jsonerror.jpg/
    Java Code:
    package com.buhz.me;
    
    import java.io.IOException;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.ClientProtocolException;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.util.EntityUtils;
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
    
    import android.app.Activity;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.widget.TextView;
    import android.widget.Toast;
    
    
    
    public class JSONTweetActivity extends Activity {
    
    	
    TextView httpStuff;
    HttpClient client;
    JSONObject json;
    
    final static String URL = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=";
    
    final 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	// TODO Auto-generated method stub
    	super.onCreate(savedInstanceState);
    	setContentView(R.layout.main);
    	httpStuff = (TextView) findViewById(R.id.tvLoad);
    	client = new DefaultHttpClient();
    	new Read().execute("text");
    	
    }
     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);
    		JSONArray timeline = new JSONArray(data);
    		JSONObject last = timeline.getJSONObject(0);
    		return last;
    	}else{
    		Toast.makeText(JSONTweetActivity.this, "error", Toast.LENGTH_SHORT);
    		return null;
    	}
     
     }
     public class Read extends AsyncTask<String, Integer, String>{
    
    	@Override
    	protected String doInBackground(String... arg0) {
    	try {
    		json = lastTweet("fresh83");
    		return json.getString(arg0[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
    	protected void onPostExecute(String result) {
    		// TODO Auto-generated method stub
    		httpStuff.setText(result);
    	}
     
     }
    
    }

  2. #2
    fresh83 is offline Member
    Join Date
    Dec 2009
    Posts
    55
    Rep Power
    0

    Default Re: Java/Android JSON Problem

    cmon....no one? no one at all even has the slightest clue whats going wrong? This is killllling me , i cant do anything until I get this figured out.

Similar Threads

  1. Replies: 0
    Last Post: 09-27-2011, 03:46 PM
  2. JSON Array Loop Inserting into Android SQLite Database
    By viviosoft in forum New To Java
    Replies: 6
    Last Post: 09-26-2011, 10:34 AM
  3. Replies: 2
    Last Post: 01-18-2011, 10:19 AM
  4. JSON Lib: json-lib-1.0-jdk13.jar
    By Raghuraman K in forum Advanced Java
    Replies: 3
    Last Post: 05-13-2010, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •