Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9031943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:51:26+00:00 2026-06-16T07:51:26+00:00

I have created new activity that my MainActivity Should lunch, some why the application

  • 0

I have created new activity that my MainActivity Should lunch, some why the application is crashing on the start of the new activity (called GamePlayActivity).
Here is the java code:

Intent startGameDrill = new Intent(MainActivity.this, GamePlayActivity.class); 
    startActivity(startGameDrill);

Here is the startGameDrill:

package com.simplemathgame;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class GamePlayActivity extends MainActivity {
    int addDrills;
    int subDrils;
    int mulDrills;
    int divDrills;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game_play);

        try {
            numberOfAddDrills = (TextView) findViewById(R.id.add_drills_number);
            numberOfSubDrills = (TextView) findViewById(R.id.sub_drills_number);
            numberOfMulDrills = (TextView) findViewById(R.id.mul_drills_number);
            numberOfDivDrills = (TextView) findViewById(R.id.div_drills_number);
            minBoundText = (TextView) findViewById(R.id.min_text);
            maxBoundText = (TextView) findViewById(R.id.max_text);
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            Log.w("game","error");
        }

        try {
            addDrills = Integer.parseInt((String) numberOfAddDrills.getText());
            subDrils = Integer.parseInt((String) numberOfSubDrills.getText());
            mulDrills = Integer.parseInt((String) numberOfMulDrills.getText());
            divDrills = Integer.parseInt((String) numberOfDivDrills.getText());
        } catch (NumberFormatException e) {
            Log.w("GameDrills","string to int");
        }
        Log.w("add", "" + addDrills);
        Log.w("add", "" + subDrils);
        Log.w("add", "" + mulDrills);
        Log.w("add", "" + divDrills);
    }

}

Here is the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.simplemathgame"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.simplemathgame.Splash"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.simplemathgame.MainActivity"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="com.simplemathgame.MainActivity" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.simplemathgame.GamePlayActivity"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
        </activity>
    </application>

</manifest>

here is the logCat:

12-21 22:05:53.949: D/dalvikvm(610): GC_EXTERNAL_ALLOC freed 42K, 53% free 2546K/5379K, external 1917K/2137K, paused 41ms
12-21 22:06:32.809: D/AndroidRuntime(610): Shutting down VM
12-21 22:06:32.809: W/dalvikvm(610): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-21 22:06:32.818: E/AndroidRuntime(610): FATAL EXCEPTION: main
12-21 22:06:32.818: E/AndroidRuntime(610): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.simplemathgame/com.simplemathgame.GamePlayActivity}: java.lang.NullPointerException
12-21 22:06:32.818: E/AndroidRuntime(610):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-21 22:06:32.818: E/AndroidRuntime(610):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-21 22:06:32.818: E/AndroidRuntime(610):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-21 22:06:32.818: E/AndroidRuntime(610):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-21 22:06:32.818: E/AndroidRuntime(610):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 22:06:32.818: E/AndroidRuntime(610):  at android.os.Looper.loop(Looper.java:123)
12-21 22:06:32.818: E/AndroidRuntime(610):  at android.app.ActivityThread.main(ActivityThread.java:3683)
12-21 22:06:32.818: E/AndroidRuntime(610):  at java.lang.reflect.Method.invokeNative(Native Method)
12-21 22:06:32.818: E/AndroidRuntime(610):  at java.lang.reflect.Method.invoke(Method.java:507)
12-21 22:06:32.818: E/AndroidRuntime(610):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-21 22:06:32.818: E/AndroidRuntime(610):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-21 22:06:32.818: E/AndroidRuntime(610):  at dalvik.system.NativeStart.main(Native Method)
12-21 22:06:32.818: E/AndroidRuntime(610): Caused by: java.lang.NullPointerException
12-21 22:06:32.818: E/AndroidRuntime(610):  at com.simplemathgame.GamePlayActivity.onCreate(GamePlayActivity.java:31)
12-21 22:06:32.818: E/AndroidRuntime(610):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-21 22:06:32.818: E/AndroidRuntime(610):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-21 22:06:32.818: E/AndroidRuntime(610):  ... 11 more

Here is the layout of the GamePlayActivity:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"
    android:background="#000044">
    <TableRow 
        android:layout_marginTop="10dp"
        android:gravity="center_vertical" >
        <TextView 
            android:textColor="#FFFFFFFF"
            android:textSize="16sp"
            android:textStyle="bold"
            android:text="Addition Drills:"/>
    </TableRow>    
</TableLayout>

Why does it crashes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:51:28+00:00Added an answer on June 16, 2026 at 7:51 am

    Have a look here:

    12-21 22:06:32.818: E/AndroidRuntime(610): Caused by: java.lang.NullPointerException
    12-21 22:06:32.818: E/AndroidRuntime(610):  at com.simplemathgame.GamePlayActivity.onCreate(GamePlayActivity.java:31)
    

    Line 31 of GamePlayActivity.java is this line:

    addDrills = Integer.parseInt((String) numberOfAddDrills.getText());
    

    Since the only thing on this line that you reference a member or method of is numberOfAddDrills, then it must be null.

    Consider that you are checking for exceptions when using findViewById; however, if the view is not found it will just return null, not throw an exception.

    Have a look at the activity_game_play.xml you posted; there is no TextView with android:id="@+id/add_drills_number". You need to create it, and the same deal for the other five TextViews.

    Oh, and a hint: Don’t just catch generic exceptions with } catch (Exception e1) {, especially if you have no intent of reading the logs. I can’t tell you how many times people have missed errors from doing this.

    If you want to pass values from another layout, you have two options: keep a reference to the View objects (this is a bit silly, don’t do this); or pass the data you need from them to your new Activity:

    startGameDrill.putExtra("myIntExtra", 5); // For example
    

    Then, in GamePlayActivity.onCreate(), you can fetch it using getIntent()‘s extras:

    Bundle extras = getIntent().getExtras();
    int myIntExtra = extras.getInt("myIntExtra");
    

    Then use that value instead of relying on the view in the previous layout. There is a fuller example in this answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application and every new created activity will start an async task
I have created a new ActionFilter for an ASP.NET MVC application that I'm creating.
I have one class called trailsActivity that extends Activity. I create a new instance
I have created a new method in one of the project's controllers that it
I have created a new silverlight business application in visual studio. It auto generates
I have created a new application using Entity Framework 4.3 database migrations. The migrations
I have TabActivityGroup: MainActivity class contain some tab, that name loading from db. Sales,
So, I have created an android activity that draws a triangle on the canvas.
I have splash activity that should download data from the url parse it and
I have created an Activity that shows a listview and on swipe action another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.