androidnoob
androidnoob

Reputation: 79

Android app unable to start activity componentInfo

app is suppose to display main homepage after splash screen, however, after splash timeout of X secs, the app crashed. Please help, I have attached the error and the following necessary codes.

Error log:

01-04 22:48:35.548: E/AndroidRuntime(28912): FATAL EXCEPTION: main
01-04 22:48:35.548: E/AndroidRuntime(28912): java.lang.RuntimeException: Unable to start activity   ComponentInfo{com.dapoaugury.channelappdemo/com.dapoaugury.channelappdemo.ChannelAppMainActivity}: java.lang.NullPointerException
01-04 22:48:35.548: E/AndroidRuntime(28912):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at android.os.Looper.loop(Looper.java:137)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at android.app.ActivityThread.main(ActivityThread.java:5419)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at java.lang.reflect.Method.invokeNative(Native Method)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at java.lang.reflect.Method.invoke(Method.java:525)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at dalvik.system.NativeStart.main(Native Method)
01-04 22:48:35.548: E/AndroidRuntime(28912): Caused by: java.lang.NullPointerException
01-04 22:48:35.548: E/AndroidRuntime(28912):    at com.dapoaugury.channelappdemo.ChannelAppMainActivity.initializeMenu(ChannelAppMainActivity.java:151)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at com.dapoaugury.channelappdemo.ChannelAppMainActivity.onCreate(ChannelAppMainActivity.java:118)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at android.app.Activity.performCreate(Activity.java:5372)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)

Splashscreen Code:

 new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                mProgress.setProgress(SPLASH_TIME_OUT);
                Intent i = new Intent(ChannelAppSplashActivity.this, ChannelAppMainActivity .class);
                startActivity(i);
                finish();
            }
        }, SPLASH_TIME_OUT);

MainActivity Code(Derived from the error log):

public void initializeMenu() {
    ChannelAppMenuAdapter mAdapter = new ChannelAppMenuAdapter(this);

    // Profile
    mAdapter.addHeader("Account");

    // Parse FB Profile data
    // ChannelAppFBDataParser fbParser = new ChannelAppFBDataParser();
    // List<UserProfile> userProfile =
    // fbParser.parse(getApplicationContext());
    // title = userProfile.get(0).getUserName();
    // icon = R.drawable.ic_profile_pic;
    // ChannelAppMenuItemModel userItem = new ChannelAppMenuItemModel(title,
    // icon);
    // mAdapter.addItem(userItem);


    //Case 1:
    title = getIntent().getExtras().getString("name");
    icon = R.drawable.ic_profile_pic;
    ChannelAppMenuItemModel userItem = new ChannelAppMenuItemModel(title,
            icon);
    mAdapter.add(userItem);

    //Case 2:
    /*title = "Settings";
    icon = R.drawable.ic_settings;
    mAdapter.addItem(title, icon);*/

    //Case 2:
    if (isLogin){
        title = "Logout";
        }
    else{
    title = "Login";
    }
    icon = R.drawable.google_icon;
    mAdapter.addItem(title, icon);


    // Channels
    mAdapter.addHeader("Channels");

    //Case 4:
    title = "Exhibition";
    icon = R.drawable.icon;
    ChannelAppMenuItemModel exhibitItem = new ChannelAppMenuItemModel(
            title, icon);
    mAdapter.addItem(exhibitItem);

    //Case 5:
    title = "Galleries";
    icon = R.drawable.icon;
    ChannelAppMenuItemModel galleryItem = new ChannelAppMenuItemModel(
            title, icon);
    mAdapter.addItem(galleryItem);

    //Case 6:
    title = "Artists";
    icon = R.drawable.icon;
    ChannelAppMenuItemModel otherItem = new ChannelAppMenuItemModel(title,
            icon);
    mAdapter.addItem(otherItem);

    mAdapter.addHeader("Products");

    //Case 8:
    title = "Search";
    icon = R.drawable.ic_action_search;
    ChannelAppMenuItemModel searchItem = new ChannelAppMenuItemModel(title,
            icon);
    mAdapter.addItem(searchItem);


    mDrawerList = (ListView) findViewById(R.id.drawer);
    if (mDrawerList != null)
        mDrawerList.setAdapter(mAdapter);

    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

}

Upvotes: 0

Views: 185

Answers (3)

Prem
Prem

Reputation: 4821

The possible answer is mentioned above. I like to share you some info on how to read your log cat window.

  1. In Logcat window, choose filter as "Error"
  2. Once filtered, at the time of application crash, look at the logs.
01-04 22:48:35.548: E/AndroidRuntime(28912): Caused by: java.lang.NullPointerException
01-04 22:48:35.548: E/AndroidRuntime(28912):    at com.dapoaugury.channelappdemo.ChannelAppMainActivity.initializeMenu(ChannelAppMainActivity.java:151)
01-04 22:48:35.548: E/AndroidRuntime(28912):    at com.dapoaugury.channelappdemo.ChannelAppMainActivity.onCreate(ChannelAppMainActivity.java:118)

Go over line by line till you see the term "Caused By"

  1. Below the line, search for your application package name.
  2. Here it will provide the line in which you might have the issue. Generally, i would recommend you to go over the method completely to find the crash.
  3. Once you know the method name, set a debugging point and run your app in debug mode. You will spot the issue easily.

Hope this helps.

Upvotes: 1

pavanmvn
pavanmvn

Reputation: 757

You are not passing tiitle using putextra to mainactivity from splash screen , so it's retreving null.

Intent i = new Intent(ChannelAppSplashActivity.this, ChannelAppMainActivity .class);
i.putExtra("name" , "tittlename");
startActivity(i);

Upvotes: 0

Greg Ennis
Greg Ennis

Reputation: 15379

Your didn't give any extras to the intent. So this line

title = getIntent().getExtras().getString("name");

crashes. Replace with

title = getIntent().getStringExtra("name");

or supply an extra to the intent called "name"

Upvotes: 2

Related Questions