2014-05-11 4 views
1

특정 활동에 자동으로 생성 된 OnCreateOptionsMenu은 기기의 옵션 버튼을 누르면 충돌합니다. 동일한 작업이 다른 작업에 액세스하는 동안 앱을 중단시키지 않습니다. 같은 앱.OnOptionsMenu가 앱을 충돌하게합니다.

logcat의 불만 중 하나는 NPE이며이 오류의 원인을 알 수 없습니다. 모든 XML 파일이 정확합니다.

자바 코드 :

 @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFormat(PixelFormat.TRANSPARENT);   
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
           WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     setContentView(R.layout.add_new_location_activity); 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.addnewloaction_optionsmenu, 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); 
    } 

} 

add_new_location_activity.xml

<?xml version="1.0" encoding="utf-8"?> 
    <FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"> 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="horizontal" 
       android:background="@color/titleBackGroundColor">    
       <RelativeLayout 
        android:id="@+id/RelativeLayout00" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="top|center_horizontal"> 
        <TextView 
         android:id="@+id/addLocationActivityTitleID" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:gravity="center" 
         android:textSize="@dimen/titlesTextSize" 
         android:text="@string/addLocationActivityTitle" 
         android:textColor="@color/titleColor"> 
        </TextView> 
       </RelativeLayout> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="horizontal">    
       <RelativeLayout 
        android:id="@+id/RelativeLayout01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"  
        android:layout_marginTop="@dimen/marginTop" 
        android:background="@color/bodyBackGroundColor"> 
        <TextView 
         android:id="@+id/editTextLabelID" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentLeft="true" 
         android:text="@string/editTextLabel" 
         android:gravity="left" 
         android:textSize="@dimen/labelsTextSizes" 
         android:textColor="@color/contentsColor">" 
        </TextView> 
        <EditText 
         android:id="@+id/editTextID" 
         android:layout_height="wrap_content" 
         android:layout_width="match_parent" 
         android:layout_toRightOf="@+id/editTextLabelID" 
         android:textColor="@color/contentsColor" 
         android:inputType="text"> 
        </EditText> 
      </RelativeLayout> 
     </LinearLayout>   
</FrameLayout> 

매니페스트 파일 :

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.meetingpointlocator_03" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="19" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.meetingpointlocator_03.Intro" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="com.example.meetingpointlocator_03.MainMenuActivity" 
      android:label="@string/title_activity_mpl" > 
     </activity> 
     <activity 
      android:name="com.example.meetingpointlocator_03.AddNewLocationActivity" 
      android:label="@string/title_activity_add_new_location" > 
     </activity> 
    </application> 

</manifest> 

로그 캣 출력 :

05-11 23:27:28.591: E/InputEventSender(2636): Exception dispatching finished signal. 
    05-11 23:27:28.596: E/MessageQueue-JNI(2636): Exception in MessageQueue callback: 
    handleReceiveCallback 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): java.lang.NullPointerException 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at 
    android.support.v7.app.ActionBarImplICS.getThemedContext(ActionBarImplICS.java:287) 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at 
    android.support.v7.app.ActionBarImplJB.getThemedContext(ActionBarImplJB.java:20) 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at android.support.v7.app.ActionBarActivityDelegate.getMenuInflater(ActionBarActivityDelegate. java:98) 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at 
    android.support.v7.app.ActionBarActivity.getMenuInflater(ActionBarActivity.java:71) 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at  
com.example.meetingpointlocator_03.AddNewLocationActivity.onCreateOptionsMenu(AddNewLocatio nActivity.java:35) 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at  
    android.app.Activity.onCreatePanelMenu(Activity.java:2578) 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at 
    android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:224) 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:232) 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at android.support.v7.app.ActionBarActivityDelegateICS.onCreatePanelMenu(ActionBarActivityDele gateICS.java:147) 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at android.support.v7.app.ActionBarActivity.onCreatePanelMenu(ActionBarActivity.java:199) 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onCreatePanelMenu (ActionBarActivityDelegateICS.java:285) 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:507) 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at com.android.internal.policy.impl.PhoneWindow.onKeyDownPanel(PhoneWindow.java:964) 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at com.android.internal.policy.impl.PhoneWindow.onKeyDown(PhoneWindow.java:1670) 
    05-11 23:27:28.626: E/MessageQueue-JNI(2636): at com. android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2227) 
+0

활동 코드 게시 – Libin

+0

업데이트를 참조하십시오. –

+0

이 활동의 ​​테마는 무엇입니까? 당신은 매니 페스트 XML을 게시 할 수 있습니까 – Libin

답변

2
causes the app to crash when I press the options button in the device 

문제는 당신이 ActionBarActivityWindow.FEATURE_NO_TITLE을 설정 한 이후의 ActionBarActivity 생성되지 않는다는 점이다. 하지만 너는 노력하고있어 inflate option menus.

대신 ActionBarActivity

public class AddNewLocationActivity extends ActionBarActivity { 

Activity을 확장 할 AddNewLocationActivity을 변경 : ActionBar 이후

getMenuInflater를 호출하려고 할 때의 ActionBar

FIX 널이 활동을 위해 만들어지지 않습니다

public class AddNewLocationActivity extends Activity { 

장치 옵션 키를 사용하여 Menus에 계속 액세스 할 수 있습니다.

+0

감사합니다. actionbaractivity가 window.feature_no_title을 사용할 때 작동하지 않습니까? –

+0

ActionBar가 필요하지 않으면 (window.feature_no_title),'ActionBarActivity'를 사용하지 않습니다. 'ActionBarActivity'의 이유는'ActionBar'로'Activity'를 지원하기 위해서입니다. – Libin