Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging adapter values in Gridview cause an exception
    text
    copied!<p>I am using a Gridview to show some TextViews in the inside. I have created a clear button that set a new Adapter with empty ArrayList and it works fine. When I tried to perform the same operation in another place, an exception happen. I have tracked all my code till I have pointed out the statement that cause the problem.</p> <p>Declairing the gridview at the first of the class</p> <pre><code>GridView gridView; </code></pre> <p>Got a reference in OnCreate method</p> <pre><code>gridView = (GridView) findViewById(R.id.gridView1); </code></pre> <p>Creating the adpater</p> <pre><code>String[] arrayEmpty = new String[] {"", "", "", "", "", "", "", "", ""}; ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;(Arrays.asList(arrayEmpty)); gridView.setAdapter(new ArrayAdapter&lt;String&gt;(this,R.layout.list_item,list));//list_item is acustomized layout for the TextView </code></pre> <p>What I am doing in Clear() method and works fine:</p> <pre><code>gridView.setAdapter(new ArrayAdapter&lt;String&gt;(MainActivity.this,R.layout.list_item,listEmpty)); </code></pre> <p>What I am doing to set the values and DOES NOT WORK:</p> <pre><code> ArrayList&lt;String&gt; gridList= new ArrayList&lt;String&gt;(); for(int i=0;i&lt;3;i++){ for(int j=0;j&lt;3;j++){ gridList.add(String.valueOf(e[i][j].getValue())); } } //The next statement cause an Exception..Why!!? gridView.setAdapter(new ArrayAdapter&lt;String&gt;(MainActivity.this,R.layout.list_item,gridList)); class solveTask extends AsyncTask&lt;Object, Void, String&gt; { @Override protected void onPreExecute() { ProgressDialog pd = new ProgressDialog(MainActivity.this); pd.setProgress(ProgressDialog.STYLE_SPINNER); pd.setMessage("Solving, please wait a few seconds..."); pd.setIndeterminate(true); pd.setCancelable(false); pd.show(); } @Override protected String doInBackground(Object... parametros) { MainActivity.this.runOnUiThread(new Runnable() { public void run() { fillSudoku(); solve(); } }); return null; } @Override protected void onPostExecute(String result) { //update progressDialog here pd.dismiss(); } } </code></pre> <p>Some of the Log:</p> <blockquote> <p>04-27 10:24:04.556: W/dalvikvm(7823): threadid=9: thread exiting with uncaught exception (group=0x40015560) 04-27 10:24:04.586: E/AndroidRuntime(7823): FATAL EXCEPTION: AsyncTask #1 04-27 10:24:04.586: E/AndroidRuntime(7823): java.lang.RuntimeException: An error occured while executing doInBackground() 04-27 10:24:04.586: E/AndroidRuntime(7823): at android.os.AsyncTask$3.done(AsyncTask.java:200) 04-27 10:24:04.586: E/AndroidRuntime(7823): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274) 04-27 10:24:04.586: E/AndroidRuntime(7823): at java.util.concurrent.FutureTask.setException(FutureTask.java:125) 04-27 10:24:04.586: E/AndroidRuntime(7823): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308) 04-27 10:24:04.586: E/AndroidRuntime(7823): at java.util.concurrent.FutureTask.run(FutureTask.java:138) 04-27 10:24:04.586: E/AndroidRuntime(7823): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 04-27 10:24:04.586: E/AndroidRuntime(7823): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 04-27 10:24:04.586: E/AndroidRuntime(7823): at java.lang.Thread.run(Thread.java:1019) 04-27 10:24:04.586: E/AndroidRuntime(7823): Caused by: java.lang.UnsupportedOperationException: removeAllViews() is not supported in AdapterView 04-27 10:24:04.586: E/AndroidRuntime(7823): at android.widget.AdapterView.removeAllViews(AdapterView.java:511) 04-27 10:24:04.586: E/AndroidRuntime(7823): at com.etaworx.thesudokusolver.MainActivity.printSudoku(MainActivity.java:481) 04-27 10:24:04.586: E/AndroidRuntime(7823): at com.etaworx.thesudokusolver.MainActivity.solve(MainActivity.java:579) 04-27 10:24:04.586: E/AndroidRuntime(7823): at com.etaworx.thesudokusolver.MainActivity$solveTask.doInBackground(MainActivity.java:625) 04-27 10:24:04.586: E/AndroidRuntime(7823): at com.etaworx.thesudokusolver.MainActivity$solveTask.doInBackground(MainActivity.java:1) 04-27 10:24:04.586: E/AndroidRuntime(7823): at android.os.AsyncTask$2.call(AsyncTask.java:185) 04-27 10:24:04.586: E/AndroidRuntime(7823): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 04-27 10:24:04.586: E/AndroidRuntime(7823): ... 4 more 04-27 10:24:09.849: E/WindowManager(7823): Activity com.etaworx.thesudokusolver.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4054e258 that was originally added here 04-27 10:24:09.849: E/WindowManager(7823): android.view.WindowLeaked: Activity com.etaworx.thesudokusolver.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4054e258 that was originally added here 04-27 10:24:09.849: E/WindowManager(7823): at android.view.ViewRoot.(ViewRoot.java:258) 04-27 10:24:09.849: E/WindowManager(7823): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148) 04-27 10:24:09.849: E/WindowManager(7823): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 04-27 10:24:09.849: E/WindowManager(7823): at android.view.Window$LocalWindowManager.addView(Window.java:424) 04-27 10:24:09.849: E/WindowManager(7823): at android.app.Dialog.show(Dialog.java:241) 04-27 10:24:09.849: E/WindowManager(7823): at com.etaworx.thesudokusolver.MainActivity.showLoading(MainActivity.java:570) 04-27 10:24:09.849: E/WindowManager(7823): at com.etaworx.thesudokusolver.MainActivity$2.onClick(MainActivity.java:77) 04-27 10:24:09.849: E/WindowManager(7823): at android.view.View.performClick(View.java:2485) 04-27 10:24:09.849: E/WindowManager(7823): at android.view.View$PerformClick.run(View.java:9080) 04-27 10:24:09.849: E/WindowManager(7823): at android.os.Handler.handleCallback(Handler.java:587) 04-27 10:24:09.849: E/WindowManager(7823): at android.os.Handler.dispatchMessage(Handler.java:92) 04-27 10:24:09.849: E/WindowManager(7823): at android.os.Looper.loop(Looper.java:123) 04-27 10:24:09.849: E/WindowManager(7823): at android.app.ActivityThread.main(ActivityThread.java:3683) 04-27 10:24:09.849: E/WindowManager(7823): at java.lang.reflect.Method.invokeNative(Native Method) 04-27 10:24:09.849: E/WindowManager(7823): at java.lang.reflect.Method.invoke(Method.java:507) 04-27 10:24:09.849: E/WindowManager(7823): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 04-27 10:24:09.849: E/WindowManager(7823): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 04-27 10:24:09.849: E/WindowManager(7823): at dalvik.system.NativeStart.main(Native Method)</p> </blockquote>
 

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