新人HelloAndroid onCreate null 指標錯誤

來源:互聯網
上載者:User

標籤:android   style   http   color   io   os   ar   java   for   

============問題描述============


按照教程來的,它自己產生的架構竟然有問題!!!簡直了。。。請大神解答!

代碼如下:(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 null 指標錯誤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.