Ok, facing the problem I can’t parse my data from inside the try{} to something outside.
What is my goal to complete here…
The for-loop will run and add a string (img) to the array (image).
Actually it parses something to the array.. but I can’t get it outside the
try/catch-block. Can somebody help me with this?
Kind regards!
protected void onPostExecute(Void unused)
{
try
{
jArray = new JSONArray(result);
String[] image = new String[jArray.length()];
Log.v("Crash Detect", "onPostExecute -> try");
JSONObject json_data=null;
for(int i=0;i<jArray.length();i++)
{
Log.v("Crash Detect", "onPostExecute -> forloop");
json_data = jArray.getJSONObject(i);
merk=json_data.getString("printerMerk");
type=json_data.getString("printerType");
content = json_data.getString("content");
img = json_data.getString("Img");
Arrays.fill(image, img);
}
}
catch(JSONException e1)
{
Toast.makeText(getBaseContext(), "Niks gevonden" ,Toast.LENGTH_LONG).show();
}
catch (ParseException e1)
{
e1.printStackTrace();
}
dialog.dismiss();
Button home = (Button) findViewById(R.id.home);
Button printerType = (Button) findViewById(R.id.printerType);
home.setText(merk);
printerType.setText(type);
list=(ListView)findViewById(R.id.list);
adapter=new LazyAdapter(doc.this, image);
list.setAdapter(adapter);
}
Declare the variable outside the try/catch and then check if it is set when you want to use it.