這已被問了很多次,並已被回答,我已經解決了這個問題,但這次卡住了,這是在一個地方工作,但在另一個活動中,它給了我以下錯誤消息。警報對話框崩潰應用程序
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
以下是我的註冊類的代碼,同樣的類是爲登錄活動編寫的,並且其工作完美。
public class RegistrationActivity extends AppCompatActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
if(sql_code.equalsIgnoreCase("0")){
String resultCode= command1.getString("result");
if(resultCode.equalsIgnoreCase("0")){
AlertDialog alertDialog = new AlertDialog.Builder(getApplicationContext()).create();
alertDialog.setTitle("Account Created");
alertDialog.setMessage("Account Created Successfully.");
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent i= new Intent(RegistrationActivity.this, LoginActivity.class);
startActivity(i);
}
});
alertDialog.show();
清單文件
<activity
android:name=".ticketing.activities.checkout.RegistrationActivity"
android:screenOrientation="portrait"
android:label="@string/title_activity_registration"
android:theme="@style/AppTheme" />
Style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:fontFamily">Roboto</item>
</style>
萬事具備,但它仍然給我這個錯誤信息,請指引我,我什麼在這裏做錯了。
可以嘗試更改「AppCompatActivity」到「活動」? –
[Android Custom Dialog]可能的重複(http://stackoverflow.com/questions/5544405/android-custom-dialog) –
可能的重複http://stackoverflow.com/questions/21814825/you-need-to-use -a-theme-appcompat-theme-or-descendant-with-this-activity –