Note that there are some explanatory texts on larger screens.

plurals
  1. POApp crashes,why is that?
    primarykey
    data
    text
    <p>So,i want to make this app that puts the EditTexts that i create dynamically in a list and then reads from that list but i'm kind of stuck,my app crashes.Could you please tell me what i'm doing wrong ?I've tested different things,tried to change some stuff but i didn't find the problem. I tried to see if it can show cant[1] but it crashes even when trying that. Here's my code : </p> <pre><code> List&lt;EditText&gt; allpret = new ArrayList&lt;EditText&gt;(); List&lt;EditText&gt; allcant = new ArrayList&lt;EditText&gt;(); public void produsnou(View v) { LinearLayout l1 = (LinearLayout) findViewById(R.id.layout1); EditText et = new EditText(this); et.setHint("Produs"); l1.addView(et); LinearLayout l2 = (LinearLayout) findViewById(R.id.layout2); EditText et2 = new EditText(this); et2.setHint("Cantitate"); et2.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); allcant.add(et2); l2.addView(et2); LinearLayout l3 = (LinearLayout) findViewById(R.id.layout3); EditText et3 = new EditText(this); et3.setHint("Pret"); et3.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); l3.addView(et3); allpret.add(et3); } public void calculeaza(View v) { String[] cant = new String[allcant.size()]; for (int j = 0; j &lt; allcant.size(); j++) { cant[j] = allcant.get(j).getText().toString(); String[] pret = new String[allcant.size()]; for (int k = 0; j &lt; allpret.size(); k++) { pret[k] = allpret.get(k).getText().toString(); } TextView totalf = (TextView) findViewById(R.id.total); totalf.setText("Total: " +cant[0]); } } </code></pre> <p>And here's logcat:</p> <pre><code>06-08 23:58:07.655: E/AndroidRuntime(7728): FATAL EXCEPTION: main 06-08 23:58:07.655: E/AndroidRuntime(7728): java.lang.IllegalStateException: Could not execute method of the activity 06-08 23:58:07.655: E/AndroidRuntime(7728): at android.view.View$1.onClick(View.java:3704) 06-08 23:58:07.655: E/AndroidRuntime(7728): at android.view.View.performClick(View.java:4232) 06-08 23:58:07.655: E/AndroidRuntime(7728): at android.view.View$PerformClick.run(View.java:17318) 06-08 23:58:07.655: E/AndroidRuntime(7728): at android.os.Handler.handleCallback(Handler.java:615) 06-08 23:58:07.655: E/AndroidRuntime(7728): at android.os.Handler.dispatchMessage(Handler.java:92) 06-08 23:58:07.655: E/AndroidRuntime(7728): at android.os.Looper.loop(Looper.java:137) 06-08 23:58:07.655: E/AndroidRuntime(7728): at android.app.ActivityThread.main(ActivityThread.java:4921) 06-08 23:58:07.655: E/AndroidRuntime(7728): at java.lang.reflect.Method.invokeNative(Native Method) 06-08 23:58:07.655: E/AndroidRuntime(7728): at java.lang.reflect.Method.invoke(Method.java:511) 06-08 23:58:07.655: E/AndroidRuntime(7728): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) 06-08 23:58:07.655: E/AndroidRuntime(7728): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 06-08 23:58:07.655: E/AndroidRuntime(7728): at dalvik.system.NativeStart.main(Native Method) 06-08 23:58:07.655: E/AndroidRuntime(7728): Caused by: java.lang.reflect.InvocationTargetException 06-08 23:58:07.655: E/AndroidRuntime(7728): at java.lang.reflect.Method.invokeNative(Native Method) 06-08 23:58:07.655: E/AndroidRuntime(7728): at java.lang.reflect.Method.invoke(Method.java:511) 06-08 23:58:07.655: E/AndroidRuntime(7728): at android.view.View$1.onClick(View.java:3699) 06-08 23:58:07.655: E/AndroidRuntime(7728): ... 11 more 06-08 23:58:07.655: E/AndroidRuntime(7728): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 3, size is 3 06-08 23:58:07.655: E/AndroidRuntime(7728): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251) 06-08 23:58:07.655: E/AndroidRuntime(7728): at java.util.ArrayList.get(ArrayList.java:304) 06-08 23:58:07.655: E/AndroidRuntime(7728): at com.example.testlayout.MainActivity.calculeaza(MainActivity.java:66) 06-08 23:58:07.655: E/AndroidRuntime(7728): ... 14 more 06-08 23:58:07.680: D/dalvikvm(7728): GC_CONCURRENT freed 237K, 11% free 7249K/8135K, paused 2ms+3ms, total 38ms 06-08 23:58:17.125: I/Process(7728): Sending signal. PID: 7728 SIG: 9 </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.
    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