首页 > 代码库 > 新人HelloAndroid onCreate 空指针错误
新人HelloAndroid onCreate 空指针错误
============问题描述============
按照教程来的,它自己生成的框架竟然有问题!!!简直了。。。请大神解答!
代码如下:(MainActivity.java)
package com.example.hello1;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Logcat报错如下:
09-25 13:00:43.170: D/AndroidRuntime(979): Shutting down VM
09-25 13:00:43.170: W/dalvikvm(979): threadid=1: thread exiting with uncaught exception (group=0xb4aa8d70)
09-25 13:00:43.190: E/AndroidRuntime(979): FATAL EXCEPTION: main
09-25 13:00:43.190: E/AndroidRuntime(979): Process: com.example.hello1, PID: 979
09-25 13:00:43.190: E/AndroidRuntime(979): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hello1/com.example.hello1.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
09-25 13:00:43.190: E/AndroidRuntime(979): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
09-25 13:00:43.190: E/AndroidRuntime(979): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
09-25 13:00:43.190: E/AndroidRuntime(979): at android.app.ActivityThread.access$800(ActivityThread.java:138)
09-25 13:00:43.190: E/AndroidRuntime(979): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
09-25 13:00:43.190: E/AndroidRuntime(979): at android.os.Handler.dispatchMessage(Handler.java:102)
09-25 13:00:43.190: E/AndroidRuntime(979): at android.os.Looper.loop(Looper.java:136)
09-25 13:00:43.190: E/AndroidRuntime(979): at android.app.ActivityThread.main(ActivityThread.java:5026)
09-25 13:00:43.190: E/AndroidRuntime(979): at java.lang.reflect.Method.invokeNative(Native Method)
09-25 13:00:43.190: E/AndroidRuntime(979): at java.lang.reflect.Method.invoke(Method.java:515)
09-25 13:00:43.190: E/AndroidRuntime(979): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
09-25 13:00:43.190: E/AndroidRuntime(979): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
09-25 13:00:43.190: E/AndroidRuntime(979): at dalvik.system.NativeStart.main(Native Method)
09-25 13:00:43.190: E/AndroidRuntime(979): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
09-25 13:00:43.190: E/AndroidRuntime(979): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
09-25 13:00:43.190: E/AndroidRuntime(979): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
09-25 13:00:43.190: E/AndroidRuntime(979): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
09-25 13:00:43.190: E/AndroidRuntime(979): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
09-25 13:00:43.190: E/AndroidRuntime(979): at android.app.Activity.setContentView(Activity.java:1930)
09-25 13:00:43.190: E/AndroidRuntime(979): at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
09-25 13:00:43.190: E/AndroidRuntime(979): at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
09-25 13:00:43.190: E/AndroidRuntime(979): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
09-25 13:00:43.190: E/AndroidRuntime(979): at com.example.hello1.MainActivity.onCreate(MainActivity.java:15)
09-25 13:00:43.190: E/AndroidRuntime(979): at android.app.Activity.performCreate(Activity.java:5242)
09-25 13:00:43.190: E/AndroidRuntime(979): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-25 13:00:43.190: E/AndroidRuntime(979): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
09-25 13:00:43.190: E/AndroidRuntime(979): ... 11 more
09-25 13:00:46.060: I/Process(979): Sending signal. PID: 979 SIG: 9
============解决方案1============
http://stackoverflow.com/questions/24587218/android-util-androidruntimeexception-you-cannot-combine-swipe-dismissal-and-the
============解决方案2============
创建虚拟机的时候不要用android4.4 ,还有把xml文件中 目标sdk换成小于20的 ,有人是这么解决的。
============解决方案3============
估计是版本问题,在猪配置文件androidmanifest 找到sdk改成你所用的版本
新人HelloAndroid onCreate 空指针错误
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。