Note that there are some explanatory texts on larger screens.

plurals
  1. POgetting error - java.lang.UnsupportedOperationException
    primarykey
    data
    text
    <p>I have written some code to set data to <code>listview</code> from a webpage. I have read the webpage successfully and stored necessary data in <code>String</code> array. Now i want to assign that to <code>ListView</code> using <code>ArrayAdapter</code> but the data is not getting set in <code>listview</code>. Please help me solve the error:</p> <p><strong>FULL LOG CAT</strong></p> <pre><code>11-07 23:41:40.150: E/AndroidRuntime(3400): FATAL EXCEPTION: main 11-07 23:41:40.150: E/AndroidRuntime(3400): java.lang.UnsupportedOperationException 11-07 23:41:40.150: E/AndroidRuntime(3400): at java.util.AbstractList.add(AbstractList.java:411) 11-07 23:41:40.150: E/AndroidRuntime(3400): at java.util.AbstractList.add(AbstractList.java:432) 11-07 23:41:40.150: E/AndroidRuntime(3400): at android.widget.ArrayAdapter.add(ArrayAdapter.java:178) 11-07 23:41:40.150: E/AndroidRuntime(3400): at com.air.test.Smscollection$sendMessageAsync.onPostExecute(Smscollection.java:91) 11-07 23:41:40.150: E/AndroidRuntime(3400): at com.air.test.Smscollection$sendMessageAsync.onPostExecute(Smscollection.java:1) 11-07 23:41:40.150: E/AndroidRuntime(3400): at android.os.AsyncTask.finish(AsyncTask.java:417) 11-07 23:41:40.150: E/AndroidRuntime(3400): at android.os.AsyncTask.access$300(AsyncTask.java:127) 11-07 23:41:40.150: E/AndroidRuntime(3400): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429) 11-07 23:41:40.150: E/AndroidRuntime(3400): at android.os.Handler.dispatchMessage(Handler.java:99) 11-07 23:41:40.150: E/AndroidRuntime(3400): at android.os.Looper.loop(Looper.java:130) 11-07 23:41:40.150: E/AndroidRuntime(3400): at android.app.ActivityThread.main(ActivityThread.java:3683) 11-07 23:41:40.150: E/AndroidRuntime(3400): at java.lang.reflect.Method.invokeNative(Native Method) 11-07 23:41:40.150: E/AndroidRuntime(3400): at java.lang.reflect.Method.invoke(Method.java:507) 11-07 23:41:40.150: E/AndroidRuntime(3400): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 11-07 23:41:40.150: E/AndroidRuntime(3400): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 11-07 23:41:40.150: E/AndroidRuntime(3400): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>Output of logcat so as to verify that data is being stored in <code>String array</code></p> <pre><code>11-07 23:03:47.640: I/NEW VAUES(3192): Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterflies 11-07 23:03:47.640: I/NEW VAUES(3192): Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterfly 11-07 23:03:47.640: I/NEW VAUES(3192): Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterfies 11-07 23:03:47.640: I/NEW VAUES(3192): Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterfly 11-07 23:03:47.640: I/NEW VAUES(3192): Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterflies 11-07 23:03:47.640: I/VALUES(3192): Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterflies&lt;br/&gt;Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterfly&lt;br/&gt;Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterfies&lt;br/&gt;Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterfly&lt;br/&gt;Happiness is Like a Butterfly, You run after it, It keeps flying away. But if you stand still, It comes and Sits On You Wish you lots of Butterflies </code></pre> <p><strong>CODE</strong></p> <pre><code>public class Smscollection extends Activity { private Spinner spinner1; private ProgressDialog pd; private StringBuilder response; private ListView listView; private String[] values = new String[0]; private ArrayAdapter&lt;String&gt; adapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_smscollection); listView = (ListView) findViewById(R.id.mylist); spinner1 = (Spinner) findViewById(R.id.spinnerCategory); spinner1.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView&lt;?&gt; av, View view, int id, long ids) { new sendMessageAsync().execute(); } public void onNothingSelected(AdapterView&lt;?&gt; av) { } }); adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, android.R.id.text1, values); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_smscollection, menu); return true; } private class sendMessageAsync extends AsyncTask&lt;Void, Void, String&gt; { @Override protected void onPreExecute() { pd = ProgressDialog.show(Smscollection.this, null, "Loading...", true, true); } @Override protected void onCancelled() { Toast.makeText(getApplicationContext(), "Message Sending Cancelled", Toast.LENGTH_LONG).show(); } @Override protected String doInBackground(Void... arg0) { try { return doInBg(); } catch (Exception ex) { ex.printStackTrace(); } return null; } @Override protected void onPostExecute(String result) { pd.dismiss(); if (result == null) { // request failed! // return; } values = String.valueOf(result).split("&lt;br/&gt;"); adapter.clear(); for (String str : values) { adapter.add(str); } adapter.notifyDataSetChanged(); listView.setAdapter(adapter); } } public String doInBg() { String responseRes = null; try { final String msgURL = "http://freesmsit.tk/msg/messages.php?category=" + String.valueOf(spinner1.getSelectedItem().toString() .replace(" ", "%20")); URLConnection connection = new URL(msgURL).openConnection(); connection.setRequestProperty("Accept-Charset", "UTF-8"); InputStream responseStream = connection.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(responseStream)); response = new StringBuilder(); String line; while ((line = br.readLine()) != null) { response.append(line); } responseRes = response.toString(); } catch (Exception ex) { ex.printStackTrace(); } return responseRes; } } </code></pre>
    singulars
    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