Android 应用程序无法启动 activity componentInfo
Android app unable to start activity componentInfo
应用程序应该在启动画面后显示主主页,但是,在启动画面超时 X 秒后,应用程序崩溃了。请帮忙,我附上了错误和以下必要的代码。
错误日志:
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.access0(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)
启动画面代码:
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 代码(源自错误日志):
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());
}
您没有提供任何额外的意图。所以这一行
title = getIntent().getExtras().getString("name");
崩溃。替换为
title = getIntent().getStringExtra("name");
或为名为 "name"
的意图提供额外的内容
您没有使用 putextra
将 tiitle
从初始屏幕传递给 mainactivity,因此它正在返回 null。
Intent i = new Intent(ChannelAppSplashActivity.this, ChannelAppMainActivity .class);
i.putExtra("name" , "tittlename");
startActivity(i);
上面提到了可能的答案。我想与您分享一些有关如何阅读日志猫的信息 window。
- 在Logcatwindow中,选择过滤器为"Error"
- 过滤后,在应用程序崩溃时,查看日志。
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)
逐行查看,直到看到 "Caused By"
- 在该行下方,搜索您的应用程序包名称。
- 此处将提供您可能遇到问题的行。通常,我会建议您完全检查该方法以找到崩溃。
- 知道方法名称后,设置调试点并运行您的应用程序处于调试模式。您会很容易发现问题。
希望对您有所帮助。
应用程序应该在启动画面后显示主主页,但是,在启动画面超时 X 秒后,应用程序崩溃了。请帮忙,我附上了错误和以下必要的代码。
错误日志:
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.access0(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)
启动画面代码:
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 代码(源自错误日志):
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());
}
您没有提供任何额外的意图。所以这一行
title = getIntent().getExtras().getString("name");
崩溃。替换为
title = getIntent().getStringExtra("name");
或为名为 "name"
的意图提供额外的内容您没有使用 putextra
将 tiitle
从初始屏幕传递给 mainactivity,因此它正在返回 null。
Intent i = new Intent(ChannelAppSplashActivity.this, ChannelAppMainActivity .class);
i.putExtra("name" , "tittlename");
startActivity(i);
上面提到了可能的答案。我想与您分享一些有关如何阅读日志猫的信息 window。
- 在Logcatwindow中,选择过滤器为"Error"
- 过滤后,在应用程序崩溃时,查看日志。
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)
逐行查看,直到看到 "Caused By"
- 在该行下方,搜索您的应用程序包名称。
- 此处将提供您可能遇到问题的行。通常,我会建议您完全检查该方法以找到崩溃。
- 知道方法名称后,设置调试点并运行您的应用程序处于调试模式。您会很容易发现问题。
希望对您有所帮助。