I connect to the server, get a Json array. Then I get all the Json objects out of it and put all the "id" key values ​​in the ArrayList . From this ArrayList I create an adapter to fill in with ListView data. The whole thing happens in AsyncTask and I can't find the reason for this error:

There is no appicable constructor to
(com.test.getArray.RegisterAccessActivity.StartAcsess, int, java.util.ArrayList)

Full class code ...

 public class RegisterAccessActivity extends Activity { String server_name = "http://dev.pareto-marketing.ru/access/"; Button test; ListView lv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.acsess); lv=(ListView)findViewById(R.id.lv); test=(Button)findViewById(R.id.test); test.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v){ StartAcsess acsess_start = new StartAcsess(); acsess_start.execute(); } }); } private class StartAcsess extends AsyncTask<Void, Void, String> { JSONArray JsonArray; JSONObject jsonobject; HttpURLConnection conn; String json_bum, bfr_st; ArrayList<String> Arraylist; ArrayAdapter<String> listAdapter; protected String doInBackground(Void... params) { try { String post_url = server_name + "index.php?load"; URL url = new URL(post_url); conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(10000); conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "Mozilla/5.0"); conn.connect(); //ΠΊΠΎΠ½Π½Π΅ΠΊΡ‚ InputStream is = conn.getInputStream(); //ΠΊΠ°Π½Π°Π» BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); StringBuilder sb = new StringBuilder(); while ((bfr_st = br.readLine()) != null) { sb.append(bfr_st); } json_bum = sb.toString(); JsonArray = new JSONArray(json_bum); is.close(); br.close(); } catch (Exception e) { } finally { conn.disconnect(); } return json_bum; } protected void onPostExecute(String json_bum) { try{ for (int u=0; u<JsonArray.length(); u++){ jsonobject = JsonArray.getJSONObject(u); Arraylist.add(jsonobject.getString("id")); //создаём массив ΠΈΠ· всСх Π·Π½Π°Ρ‡Π΅Π½ΠΈΠΉ } listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, Arraylist); lv.setAdapter(listAdapter); } catch (Exception e) { } finally{ } } } } 

About the server and the correctness of the array - the data without any problems were displayed in TextView. Problem creating adapter ...

SOLUTION =)

New onPostExecute ()

 protected void onPostExecute(String json_bum) { try{ arraylist=new ArrayList(); //инициализация for (int u=0; u<JsonArray.length(); u++) { jsonobject = JsonArray.getJSONObject(u); arraylist.add(jsonobject.getString("id")); } listAdapter = new ArrayAdapter<String>(RegisterAccessActivity.this, R.layout.simplerow, arraylist); lv.setAdapter(listAdapter); } catch (Exception e) { } finally { } } 
  • Initialize your Arraylist - temq

1 answer 1

The first argument is the ArrayAdapter class constructor ArrayAdapter takes a context, you pass this , which is written inside the StartAcsess class StartAcsess contains a link to it, not the required Context .

Decision:

Change this to RegisterAccessActivity.this or, better yet, pass the context through the task constructor.

  • @ SergeyGrushin, your list is not initialized, i.e. null Why is this - only you should know) And by the way, the names of the variables should be in small letters - rename your ArrayList - YuriSPb ♦
  • thank you so much)) after initializing and renaming the variable, the ListView is finally ready! - Flippy