应用程序假设在启动画面后显示主页面,但是,在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.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代码:
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(源自错误日志):
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());
}
答案 0 :(得分:2)
你没有给意图添加任何额外内容。所以这一行
title = getIntent().getExtras().getString("name");
崩溃。替换为
title = getIntent().getStringExtra("name");
或提供名为&#34; name&#34;
的意图答案 1 :(得分:1)
上面提到了可能的答案。我想分享一些关于如何阅读日志猫窗口的信息。
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)
逐行检查直到你看到“&#34;
引起的术语”希望这有帮助。
答案 2 :(得分:0)
您没有使用tiitle
将putextra
传递给来自初始屏幕的主要活动,因此它正在撤消null。
Intent i = new Intent(ChannelAppSplashActivity.this, ChannelAppMainActivity .class);
i.putExtra("name" , "tittlename");
startActivity(i);