Note that there are some explanatory texts on larger screens.

plurals
  1. POForce Closes on Opening Activity
    text
    copied!<p>I am working on an app where you touch the screen and the basketball moves there. I am almost there except it force closes when you open this mini-app from a list of activities to start. After scanning through several times I could not find anything.</p> <p>This is my Java Class and after is the Logcat:</p> <pre><code>package com.frostbytedev.addsub; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.os.Bundle; import android.view.MotionEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.View.OnTouchListener; public class SurfaceViewExample extends Activity implements OnTouchListener { OurView v; Bitmap ball; float x = 0; float y = 0; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); v = new OurView(this); setContentView(v); v.setOnTouchListener(this); ball = BitmapFactory.decodeResource(getResources(), R.drawable.bball); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); v.pause(); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); v.resume(); } public class OurView extends SurfaceView implements Runnable { Thread t = null; SurfaceHolder holder; boolean isItOkay = false; public OurView(Context context) { super(context); // TODO Auto-generated constructor stub holder = getHolder(); } @Override public void run() { // TODO Auto-generated method stub while(isItOkay) { if(!holder.getSurface().isValid()){ continue; } Canvas c = holder.lockCanvas(); c.drawARGB(255, 150, 150, 150); c.drawBitmap(ball, x-(ball.getWidth()/2), y-(ball.getHeight()/2), null); holder.unlockCanvasAndPost(c); } } public void pause(){ isItOkay = false; while(true){ try{ t.join(); } catch(InterruptedException e){ e.printStackTrace(); } } } public void resume() { isItOkay = true; t = new Thread(this); t.start(); } } @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub x = event.getX(); y = event.getY(); return false; } } </code></pre> <p>Logcat:</p> <pre><code>05-09 19:24:35.730: D/libEGL(8218): loaded /system/lib/egl/libEGL_adreno200.so 05-09 19:24:35.740: D/libEGL(8218): loaded /system/lib/egl/libGLESv1_CM_adreno200.so 05-09 19:24:35.750: D/libEGL(8218): loaded /system/lib/egl/libGLESv2_adreno200.so 05-09 19:24:35.800: D/OpenGLRenderer(8218): Enabling debug mode 0 05-09 19:24:44.658: D/AndroidRuntime(8218): Shutting down VM 05-09 19:24:44.658: W/dalvikvm(8218): threadid=1: thread exiting with uncaught exception (group=0x40a7a930) 05-09 19:24:44.668: E/AndroidRuntime(8218): FATAL EXCEPTION: main 05-09 19:24:44.668: E/AndroidRuntime(8218): java.lang.ArrayIndexOutOfBoundsException: length=5; index=5 05-09 19:24:44.668: E/AndroidRuntime(8218): at com.frostbytedev.addsub.Menu.onListItemClick(Menu.java:25) 05-09 19:24:44.668: E/AndroidRuntime(8218): at android.app.ListActivity$2.onItemClick(ListActivity.java:319) 05-09 19:24:44.668: E/AndroidRuntime(8218): at android.widget.AdapterView.performItemClick(AdapterView.java:298) 05-09 19:24:44.668: E/AndroidRuntime(8218): at android.widget.AbsListView.performItemClick(AbsListView.java:1102) 05-09 19:24:44.668: E/AndroidRuntime(8218): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2751) 05-09 19:24:44.668: E/AndroidRuntime(8218): at android.widget.AbsListView$1.run(AbsListView.java:3426) 05-09 19:24:44.668: E/AndroidRuntime(8218): at android.os.Handler.handleCallback(Handler.java:725) 05-09 19:24:44.668: E/AndroidRuntime(8218): at android.os.Handler.dispatchMessage(Handler.java:92) 05-09 19:24:44.668: E/AndroidRuntime(8218): at android.os.Looper.loop(Looper.java:137) 05-09 19:24:44.668: E/AndroidRuntime(8218): at android.app.ActivityThread.main(ActivityThread.java:5237) 05-09 19:24:44.668: E/AndroidRuntime(8218): at java.lang.reflect.Method.invokeNative(Native Method) 05-09 19:24:44.668: E/AndroidRuntime(8218): at java.lang.reflect.Method.invoke(Method.java:511) 05-09 19:24:44.668: E/AndroidRuntime(8218): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799) 05-09 19:24:44.668: E/AndroidRuntime(8218): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566) 05-09 19:24:44.668: E/AndroidRuntime(8218): at dalvik.system.NativeStart.main(Native Method) </code></pre>
 

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