当我点击任何 listview 行时,它会显示 IllegalStateException ,而不是显示警告对话框。 它说要使用 Theme.AppCompat 主题。我不太了解这一点,我很新,任何人都可以帮助我了解所有这些appcompat活动以及造成这种麻烦的原因。
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:355)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:324)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:285)
at android.support.v7.app.AppCompatDialog.setContentView(AppCompatDialog.java:83)
at android.support.v7.app.AlertController.installContent(AlertController.java:225)
at android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:257)
at android.app.Dialog.dispatchOnCreate(Dialog.java:397)
at android.app.Dialog.show(Dialog.java:298)
at com.example.stark.messenger.showDatabase$1.onItemClick(showDatabase.java:93)
at android.widget.AdapterView.performItemClick(AdapterView.java:310)
at android.widget.AbsListView.performItemClick(AbsListView.java:1145)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3081)
at android.widget.AbsListView$3.run(AbsListView.java:3947)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
我的主要活动的代码是:
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import java.util.ArrayList;
public class showDatabase extends AppCompatActivity {
SQLiteOpenHelper expensedatabase;
SQLiteDatabase db;
Cursor cursor;
ListView lv;
ArrayList<DataModel> dataModels;
private static CustomAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_database);
lv=(ListView) findViewById(R.id.lv_custom_list);
expensedatabase = new ExpenseDatabase(this);
db = expensedatabase.getReadableDatabase();
}
protected void onStart()
{
super.onStart();
dataModels = new ArrayList<DataModel>();
dataModels.clear();
cursor = db.rawQuery("select * from ExpenseRecord where strftime('%Y-%m', DATE) = '2017-04';",null);
if (cursor != null && cursor.getCount() != 0) {
if (cursor.moveToFirst()) {
do {
DataModel datamodelItems = new DataModel();
datamodelItems.setPayee(cursor.getString(cursor
.getColumnIndex("PAYEE")));
datamodelItems.setAmount(cursor.getString(cursor
.getColumnIndex("AMOUNT")));
datamodelItems.setCategory(cursor.getString(cursor
.getColumnIndex("CATEGORY")));
datamodelItems.setNotes(cursor.getString(cursor
.getColumnIndex("NOTES")));
datamodelItems.setDate(cursor.getString(cursor
.getColumnIndex("DATE")));
datamodelItems.setTime(cursor.getString(cursor
.getColumnIndex("TIME")));
dataModels.add(datamodelItems);
} while (cursor.moveToNext());
}
}
cursor.close();
CustomAdapter customadapter = new CustomAdapter(dataModels,getApplicationContext());
lv.setAdapter(customadapter);
lv.setOnItemClickListener(itemlistener);
}
AdapterView.OnItemClickListener itemlistener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(getApplicationContext());
builder.setView(R.layout.dialog_box)
.setPositiveButton("Update", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
//update click
}
})
.setNeutralButton("Disable", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
//disable click
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
//cancel click
}
});
if(position>-1) {
android.support.v7.app.AlertDialog alert = builder.create();
alert.show();
}
}
};
public void onDestroy(){
super.onDestroy();
cursor.close();
db.close();
}
}
答案 0 :(得分:0)
尝试添加
abstracts <- lapply(mytxtfiles, function(i) {
j <- paste0(scan(i, what = character()), collapse = " ")
regmatches(j, gregexpr("(?m)(^[^\\r\\n]*\\R+){4}[cancer][^\\r\\n]*\\R+(^[^\\r\\n]*\\R+){4}", j, perl=TRUE))})
到AndroidManifest.xml文件中的应用程序标记。
正如本文所述。
You need to use a Theme.AppCompat theme (or descendant) with this activity