Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot use "this" in a static content in android
    primarykey
    data
    text
    <p>I am using simple list adapter in my android application</p> <pre><code> ListAdapter adapter = new SimpleAdapter(this, jsonParseList , R.layout.list_view, new String[] {"conv_title","content"}, new int[] { R.id.conv_title, R.id.content }); listView.setAdapter(adapter); </code></pre> <p>In the above code in the place of <code>this</code> it shows <code>this</code> cannot use in a static content. Why?</p> <pre><code>public class Json extends Activity { static HttpURLConnection urlConnection; static ListView listView; //ArrayList&lt;String&gt; jsonParseList = new ArrayList&lt;String&gt;(); Jsonparser jsonparser; enter code here @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.json_main); listView = (ListView) findViewById(android.R.id.list); jsonparser = new Jsonparser(); jsonparser.execute(""); Log.e("List Activity", "" + jsonParseList); } public static HttpURLConnection openConnection() throws Exception { int responseCode = -1; try { URL url = new URL( " place ur url"); urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("POST"); urlConnection.setRequestProperty("Content-Type", "application/x-www-form-encoded"); urlConnection .setRequestProperty( "Content-Length", "" + Integer .toString("place ur url" .getBytes().length)); urlConnection.setRequestProperty("Content-Language", "en-US"); urlConnection.setRequestProperty("Accept-Encoding", "identity"); urlConnection.setUseCaches(false); urlConnection.setDoInput(true); urlConnection.setDoOutput(true); urlConnection.setReadTimeout(10 * 1000); urlConnection.setConnectTimeout(10 * 1000); DataOutputStream wr = new DataOutputStream( urlConnection.getOutputStream()); wr.writeBytes("place ur url"); wr.flush(); wr.close(); responseCode = urlConnection.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) { throw new Exception("Server not responding"); } } catch (SocketException e) { throw new Exception("Connection Time Out"); } catch (java.net.UnknownHostException unknownHostException) { // TODO: handle exception throw new Exception("unknownHostException"); } catch (Exception e) { // TODO: handle exception throw new Exception("Error Occured"); } return urlConnection; } public static ArrayList&lt;String&gt; jsonParseList = new ArrayList&lt;String&gt;(); public static ArrayList&lt;String&gt; jsonParsing() { // TODO Auto-generated method stub StringBuffer buffer = new StringBuffer(); JSONArray array; try { try { urlConnection = openConnection(); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(urlConnection.getInputStream())); String line = bufferedReader.readLine(); while (line != null) { buffer.append(line); line = bufferedReader.readLine(); } bufferedReader.close(); if (buffer.toString() != null) { try { array = new JSONArray(buffer.toString()); JSONObject jsonObject; for (int i = 0; i &lt; array.length(); i++) { jsonObject = array.getJSONObject(i); String conv_title = jsonObject.getString("conv_title"); String content = jsonObject.getJSONObject("first_post") .getString("content"); String creator = jsonObject.getJSONObject("first_post") .getJSONObject("creator").getString("name"); HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); // adding each child node to HashMap key =&gt; value //map.put("id", String.valueOf(i)); map.put("conv_title", jsonObject.getString("conv_title")); map.put("content", jsonObject.getString("content")); map.put(conv_title, conv_title); map.put(content, content); Log.e("List Values", conv_title); Log.e("List Values", content); jsonParseList.add("conv_title "+"content"); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } ListAdapter adapter = new SimpleAdapter(this, jsonParseList , R.layout.list_view, new String[] {"conv_title","content"}, new int[] { R.id.conv_title, R.id.content }); listView.setAdapter(adapter); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jsonParseList; } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } private class Jsonparser extends AsyncTask&lt;String, Void, ArrayList&lt;String&gt;&gt; { @Override protected ArrayList&lt;String&gt; doInBackground(String... params) { // TODO Auto-generated method stub return jsonUtil.jsonParsing(); } @Override protected void onPostExecute(ArrayList&lt;String&gt; result) { // TODO Auto-generated method stub super.onPostExecute(result); if (result instanceof ArrayList&lt;?&gt;) { jsonParseList = result; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload