我不知道如何處理這個問題,我想我已到處搜索。但是這個問題只是神祕的。我有一個名爲EditdataActivity無法使用Theme.Dialog啓動活動
public class EditdataActivity extends ActionBarActivity{
logclass clogs = new logclass();
EditText edt_ln;
EditText edt_lat;
EditText edt_long;
Button btn_cancel;
Button btn_save;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dataedit);
clogs =(logclass) getIntent().getSerializableExtra("MyClass");
edt_ln = (EditText) findViewById(R.id.edt_Ln);
edt_lat = (EditText) findViewById(R.id.edt_lat);
edt_long = (EditText) findViewById(R.id.det_long);
btn_cancel = (Button) findViewById(R.id.cancel_btn);
btn_save = (Button) findViewById(R.id.btn_save);
edt_ln.setText(clogs.getname());
edt_lat.setText(clogs.getlatloc()+"");
edt_long.setText(clogs.getlongloc()+"");
OnClickListener savelistener = new OnClickListener() {
@Override
public void onClick(View v) {
//notifpopup("Save changes?");
}
};
btn_save.setOnClickListener(savelistener);
OnClickListener cancellistener = new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent1 = new Intent(EditdataActivity.this, AdddataclassActivity.class);
intent1.putExtra("MyClass", clogs);
intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent1);
overridePendingTransition (R.anim.open_main, R.anim.close_next);
}
};
btn_cancel.setOnClickListener(cancellistener);
}
void notifpopup(String notif){
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(notif);
alert.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
clogs.setname(edt_ln.getText().toString());
double lat = Double.parseDouble(edt_lat.getText().toString());
double longl = Double.parseDouble(edt_long.getText().toString());
clogs.setlatloc(lat);
clogs.setlongloc(longl);
}
});
alert.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.show();
}
}
的活動,這是從這個活動
@Override
protected void onCreate(Bundle savedInstanceState) {
........
clogs =(logclass) getIntent().getSerializableExtra("MyClass");
........
Button edit_data = (Button) findViewById(R.id.btn_addattrbdel);
OnClickListener editlistener = new OnClickListener() {
@Override
public void onClick(View v) {
gotoeditview();
}
};
edit_data.setOnClickListener(editlistener);
}
void gotoeditview(){
Intent intentl = new Intent(this,EditdataActivity.class);
intentl.putExtra("MyClass", clogs);
intentl.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intentl);
overridePendingTransition (R.anim.appear, R.anim.disappear);
}
稱爲然而,當我執行它,如在logcat的beloc
10-17 17:06:41.750: E/AndroidRuntime(707): FATAL EXCEPTION: main
10-17 17:06:41.750: E/AndroidRuntime(707): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ict.map_navigation/com.ict.map_navigation.EditdataActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
10-17 17:06:41.750: E/AndroidRuntime(707): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
10-17 17:06:41.750: E/AndroidRuntime(707): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2095)
10-17 17:06:41.750: E/AndroidRuntime(707): at android.app.ActivityThread.access$600(ActivityThread.java:134)
10-17 17:06:41.750: E/AndroidRuntime(707): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
10-17 17:06:41.750: E/AndroidRuntime(707): at android.os.Handler.dispatchMessage(Handler.java:99)
10-17 17:06:41.750: E/AndroidRuntime(707): at android.os.Looper.loop(Looper.java:137)
10-17 17:06:41.750: E/AndroidRuntime(707): at android.app.ActivityThread.main(ActivityThread.java:4830)
10-17 17:06:41.750: E/AndroidRuntime(707): at java.lang.reflect.Method.invokeNative(Native Method)
10-17 17:06:41.750: E/AndroidRuntime(707): at java.lang.reflect.Method.invoke(Method.java:511)
10-17 17:06:41.750: E/AndroidRuntime(707): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
10-17 17:06:41.750: E/AndroidRuntime(707): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
10-17 17:06:41.750: E/AndroidRuntime(707): at dalvik.system.NativeStart.main(Native Method)
10-17 17:06:41.750: E/AndroidRuntime(707): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
10-17 17:06:41.750: E/AndroidRuntime(707): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
10-17 17:06:41.750: E/AndroidRuntime(707): ....
發生錯誤..但正如我已經讀過一些建議的解決方案,我將我的EditDataActivity更改爲Acitvity ..它沒有任何錯誤..但它只顯示此..
,併爲該活動我的XML文件是這樣的..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="Change Name of the Location" />
<EditText
android:id="@+id/edt_Ln"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView1"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/edt_Ln"
android:gravity="center"
android:text="Change Location" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView3"
android:layout_marginTop="26dp"
android:text="Longitude:"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView2"
android:layout_marginTop="28dp"
android:text="Latitude:"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="@+id/edt_lat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView3"
android:layout_alignBottom="@+id/textView3"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/textView4"
android:ems="10"
android:inputType="number" />
<EditText
android:id="@+id/det_long"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView4"
android:layout_alignBottom="@+id/textView4"
android:layout_alignLeft="@+id/edt_lat"
android:layout_alignParentRight="true"
android:ems="10"
android:inputType="number" />
<Button
android:id="@+id/btn_save"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/det_long"
android:layout_marginTop="17dp"
android:layout_toRightOf="@+id/btn_cancel"
android:background="#00ced1"
android:text="Save" />
<Button
android:id="@+id/btn_cancel"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_save"
android:layout_alignBottom="@+id/btn_save"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/textView4"
android:background="#ff0000"
android:text="Cancel" />
</RelativeLayout>
我有其他活動而這正是像這樣在我的項目。但他們都工作正常,我試過..重新啓動我的Eclipse IDE ..但它沒有工作..請幫助,也許我只是忘了一些東西。感謝..這裏是我的項目的清單文件..
對不起,我長的帖子...
是什麼THR在ActionBarActivityDelegate.java:110,並張貼烏爾ActionBarActivityDelegate.java文件太多。 – 2014-10-17 09:25:06
IllegalStateException,在VM未處於正確狀態時嘗試執行操作時引發。 – 2014-10-17 09:28:20
請點擊此鏈接:http://stackoverflow.com/questions/21814825/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity – prakash 2014-10-17 09:30:45