2017-09-06 202 views
-1

我正在製作一個活動,必須在開始時將對話框顯示爲註冊表單。但是,該活動總是崩潰。 以下是該活動的代碼:Android對話框崩潰應用程序

public class CheckInActivity extends AppCompatActivity{ 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_check_in); 
    getDialogue(); 



} 

public void getDialogue(){ 

    //Pop dialogue 

    AlertDialog.Builder mBuilder= new AlertDialog.Builder(getApplicationContext()); 
    View mView= getLayoutInflater().inflate(R.layout.dialog_register, null); 
    final EditText mPhone= (EditText) mView.findViewById(R.id.etPhone); 
    final EditText mPass= (EditText) mView.findViewById(R.id.etPass); 
    final EditText mRtPass= (EditText) mView.findViewById(R.id.etRtPass); 
    Button mRegisterButton = (Button) mView.findViewById(R.id.btnRegister); 


    mBuilder.setView(mView); 
    AlertDialog dialog= mBuilder.create(); 
    dialog.show(); 

} 
} 

這裏是activity_check_in.xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.shashank_pc.trial.CheckInActivity"> 

</android.support.constraint.ConstraintLayout> 

這裏是在android_manifest.xml文件中的活動

<activity android:name=".CheckInActivity" 
     android:theme="@style/Theme.AppCompat"> 

     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

    </activity> 

的錯誤消息如下:

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 

請幫忙!!

回答

0

嘗試AlertDialog.Builder mBuilder= new AlertDialog.Builder(this);

+0

這不提供問題的答案。要批評或要求作者澄清,請在其帖子下方留言。 - [來自評論](/ review/low-quality-posts/17255671) – FluffyKitten

0

只需更換這行

AlertDialog.Builder mBuilder= new AlertDialog.Builder(getApplicationContext()); 

android.support.v7.app.AlertDialog.Builder mBuilder= new android.support.v7.app.AlertDialog.Builder(getApplicationContext()); 

或者只是添加android:theme="@style/Theme.AppCompat.Light"到應用程序標籤在AndroidManifest.xml文件。

+0

沒用。仍然崩潰 – Thanatos