Unhandled exception type JSONException

daxsn

Mitglied
Moin,

ich habe eine Backgroundfunktion in der daten von meinem Server geladen werden und die ich in einen Array packe.

Java:
public class LoadData extends AsyncTask<Void, Void, Void> {
	    ProgressDialog progressDialog;
	    //declare other objects as per your need
	    @Override
	    protected void onPreExecute()
	    {
               
	    };      
	    @Override
	    protected Void doInBackground(Void... params)
	    {   
			////////////////////////////////////////////////////////////////////////////////////////AUSLESEN SPIELER
	    	InputStream is = null;		
		    //POST DATEN
		    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		    nameValuePairs.add(new BasicNameValuePair("pin","15487632Phua4"));	
		    nameValuePairs.add(new BasicNameValuePair("datenbank","spieler"));	
		
		   	//HTTP VERBINDUNG
		    try{
		            HttpClient httpclient = new DefaultHttpClient();
		            HttpPost httppost = new HttpPost(KEY_121);
		            //POST DATEN ABSCHICKEN
		            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
		            HttpResponse response = httpclient.execute(httppost);
		            HttpEntity entity = response.getEntity();
		            is = entity.getContent();
		    }catch(Exception e){
		            Log.e("log_tag", "Error in http connection "+e.toString());
		    }
		    //IN STRING UMWANDELN
		    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();
		            result=sb.toString();
		    }catch(Exception e){
		            Log.e("log_tag", "Error converting result "+e.toString());
		    }
		    try{
		    	jArray = new JSONArray(result);
		    }catch(Exception e){
	            Log.e("log_tag", "Error converting result "+e.toString());
		    }
	        return null;
	    }       
	    @Override
	    protected void onPostExecute(Void result)
	    {
	        super.onPostExecute(result);
	        getServerData();
	    };
}
Nun möchte ich von der getServerData den Array in seine Zeilen füllen:
Java:
private void getServerData() {
for(int i=0;i<jArray.length();i++){
                JSONObject json_data = jArray.getJSONObject(i);

Nur leider sagt mir Eclipse:

Unhandled exception type JSONException


public JSONArray jArray; ist definiert.

Was mache ich falsch?
 
Zuletzt bearbeitet von einem Moderator:
A

asdfghjl

Gast
Das hat nichts mit der Definiton zu tun, die Methode kann eine Exception werfen, die vom Programmierer abgefangen werden muss. Einfach mal nach
Code:
Java Exceptionhandling
suchen.
 

Ähnliche Java Themen

Neue Themen


Oben