Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Application crash with Application has Stopped
    primarykey
    data
    text
    <p>My Android app compiles fine but crashed with the message Application has stopped. What is the problem with my code?</p> <pre><code>#GameView.java public class GameView extends View { public Bitmap droid; public Matrix translate; public GameView(Context context) { super(context); droid = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); } public void onDraw(Canvas canvas) { canvas.drawBitmap(droid, 10, 10, null); } #Game.java public class Game extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FrameLayout view = (FrameLayout)findViewById(R.id.graphics_holder); view.addView(new GameView(this)); setContentView(R.layout.game); </code></pre> <p>LogCat</p> <pre><code>07-18 04:48:05.517: E/AndroidRuntime(960): FATAL EXCEPTION: main 07-18 04:48:05.517: E/AndroidRuntime(960): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.oop/com.example.oop.Game}: java.lang.NullPointerException 07-18 04:48:05.517: E/AndroidRuntime(960): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) 07-18 04:48:05.517: E/AndroidRuntime(960): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 07-18 04:48:05.517: E/AndroidRuntime(960): at android.app.ActivityThread.access$600(ActivityThread.java:130) 07-18 04:48:05.517: E/AndroidRuntime(960): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 07-18 04:48:05.517: E/AndroidRuntime(960): at android.os.Handler.dispatchMessage(Handler.java:99) 07-18 04:48:05.517: E/AndroidRuntime(960): at android.os.Looper.loop(Looper.java:137) 07-18 04:48:05.517: E/AndroidRuntime(960): at android.app.ActivityThread.main(ActivityThread.java:4745) 07-18 04:48:05.517: E/AndroidRuntime(960): at java.lang.reflect.Method.invokeNative(Native Method) 07-18 04:48:05.517: E/AndroidRuntime(960): at java.lang.reflect.Method.invoke(Method.java:511) 07-18 04:48:05.517: E/AndroidRuntime(960): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 07-18 04:48:05.517: E/AndroidRuntime(960): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 07-18 04:48:05.517: E/AndroidRuntime(960): at dalvik.system.NativeStart.main(Native Method) 07-18 04:48:05.517: E/AndroidRuntime(960): Caused by: java.lang.NullPointerException 07-18 04:48:05.517: E/AndroidRuntime(960): at com.example.oop.Game.onCreate(Game.java:19) 07-18 04:48:05.517: E/AndroidRuntime(960): at android.app.Activity.performCreate(Activity.java:5008) 07-18 04:48:05.517: E/AndroidRuntime(960): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 07-18 04:48:05.517: E/AndroidRuntime(960): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 07-18 04:48:05.517: E/AndroidRuntime(960): ... 11 more </code></pre> <p>If I change to this it works</p> <pre><code>public class Game extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // FrameLayout view = (FrameLayout)findViewById(R.id.graphics_holder); // view.addView(); setContentView(new GameView(this)); } } </code></pre> <p>But my intention is to use a frame to encapsulate what I want to display because my layout has other GUI objects to show.</p> <p>My layout file game.xml</p> <pre><code> &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="@dimen/padding_large" &gt; &lt;FrameLayout android:id="@+id/graphics_holder" android:layout_width="300dp" android:layout_height="400dp" android:layout_centerHorizontal="true" android:layout_centerVertical="true" &gt; &lt;/FrameLayout&gt; &lt;TextView android:id="@+id/bpm" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="TextView" android:textSize="@dimen/padding_large" /&gt; &lt;/RelativeLayout&gt; </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