json parser to spinner

Please help
im newbie for android
and im try to make json parse with spinner with this code, but i have an error message “java.lang.NullPointerException”, please help to fix my code..

@SuppressWarnings("deprecation")
public class evaluasi extends Activity{

InputStream is = null;
String result = null;
String line = null;
JSONObject jsonobject;
JSONArray jsonarray;
ArrayList<String> worldlist;

@Override
protected void onCreate (Bundle savedInstanceState){
     super.onCreate(savedInstanceState);
     setContentView(R.layout.lay_evaluasi);

     /*parsing ke broker*/
     try{
         HttpClient httpclient = new DefaultHttpClient();
         HttpPost httppost = new HttpPost("http://www.androidbegin.com/tutorial/jsonparsetutorial.txt");
         HttpResponse response = httpclient.execute(httppost);
         HttpEntity entity = response.getEntity();
         is = entity.getContent();
         Log.e("Pass 1", "Sucsess..");
     }catch (Exception e){
         Log.e("Fail 1", e.toString());
         Toast.makeText(getApplicationContext(), "Invalid IP Address", Toast.LENGTH_SHORT).show();
     }

     try{
         BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
         StringBuilder sb = new StringBuilder();
         while((line = reader.readLine()) !=null )
         {
             sb.append(line + "n");
         }
         is.close();
         result = sb.toString();
         Log.e("Pass 2", "Connection Sucess");
     }catch (Exception e){
         Log.e("Fail 2", "Failed Connection");
     }

     try{

         worldlist =new ArrayList<String>();
         jsonarray = jsonobject.getJSONArray("worldpopulation");
         for (int i = 0; i < jsonarray.length(); i++) {
             worldlist.add(jsonobject.optString("country"));
         }

    Spinner spinbro = (Spinner) findViewById(R.id.spinbrokced);
    spinbro.setAdapter(new ArrayAdapter<String>(evaluasi.this,
            android.R.layout.simple_spinner_dropdown_item,
            worldlist));

     }catch (Exception e){
         Log.e("Fail 3", e.toString());
         Toast.makeText(getApplicationContext(), "cant load data", Toast.LENGTH_SHORT).show();
     }

}
        //end parsin broker


Source: json

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.