我得到错误的关闭()从来没有显式调用一次又一次启动应用程序。我不明白我在数据库中哪里错了。
这是我的密码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mLayout = (MainLayout) this.getLayoutInflater().inflate(R.layout.all_post, null);
setContentView(mLayout);
dbhelper = new MyDbHelper(this);
imgLeftmenu = (ImageView) findViewById(R.id.imgLeftMenu);
imgSearch = (ImageView) findViewById(R.id.imgSearch);
imgAdd = (ImageView) findViewById(R.id.imgAdd);
listView = (ListView) findViewById(R.id.listview_AllPost);
populateList();
new GetgetDoenLoaddata().execute();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
str_Authentication_Token = sharedPreferences.getString("strAuthentication_Token", "");
str_UserId = sharedPreferences.getString("strUserId", "");
Log.e("Prefs", "str_Authentication_Token = " + str_Authentication_Token + "Prefs str_UserId = " + str_UserId);
SQLiteDatabase db = dbhelper.getWritableDatabase();
String query = "select * from SyncTime where WebServiceEntity ='" + "AllPost_ActivityList" + "'";
Cursor cursor = db.rawQuery(query, null);
while (cursor.moveToNext()) {
strSyncTime = cursor.getString(cursor.getColumnIndex("SyncTime"));
strSyncTime1 = strSyncTime.replaceAll(" ", "%20");
Log.e("strSyncTime ", " = " + strSyncTime1);
}
cursor.close();
Intent intent = getIntent();
String newAudioFile = intent.getStringExtra("newAudioFile");
Log.e("newAudioFile ", " = " + newAudioFile);
imgAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(AllPosts_Page.this, AddPost.class);
startActivity(i);
}
});
imgSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
private void populateList() {
descArray.clear();
List<All_Post> allDesc = dbhelper.getAllDescriptions();
for (All_Post all_Post : allDesc) {
descArray.add(all_Post);
}
if (adapter == null) {
adapter = new MyListAdapter(this, R.layout.all_post_row, descArray);
listView.setAdapter(adapter);
Log.e("Single Entry ", " !!!! ");
} else if (adapter != null) {
adapter.notifyDataSetChanged();
Log.e("Double Entry ", " !!!! ");
adapter = new MyListAdapter(this, R.layout.all_post_row, descArray);
listView.setAdapter(adapter);
}
}
@Override
protected void onResume() {
super.onResume();
populateList();
}
@Override
protected void onDestroy() {
super.onDestroy();
if (dbhelper != null) {
dbhelper.close();
}
}
public void getDoenLoaddata() {
dbhelper = new MyDbHelper(this);
SQLiteDatabase db1 = dbhelper.getWritableDatabase();
Cursor cursor = db1.rawQuery("select * from ActivityObjectList", null);
if (cursor.moveToFirst()) {
do {
imageName = cursor.getString(cursor.getColumnIndex("imageaudioPath"));
String strDownLoadStatus = cursor.getString(cursor.getColumnIndex("DownLoad_Status"));
if (strDownLoadStatus.equalsIgnoreCase("0")) {
if (imageName.endsWith(mp3_Pattern)) {
str_DownLoadUrl = namespace + "/DownloadFile/FileName/" + imageName;
DownLoadAudioFile(str_DownLoadUrl, imageName);
strDownLoadStatus = "1";
dbhelper.update_DownLoadStatus(imageName, strDownLoadStatus);
}
if (imageName.endsWith(png_Pattern) || imageName.endsWith(jpg_pattern) || imageName.endsWith(bmp_pattern) || imageName.endsWith(gif_pattern) || imageName.endsWith(jpeg_pattern)) {
str_DownLoadUrl = namespace + "/DownloadFile/FileName/" + imageName;
download_PngFile(str_DownLoadUrl, imageName);
strDownLoadStatus = "1";
dbhelper.update_DownLoadStatus(imageName, strDownLoadStatus);
}
}
}
while (cursor.moveToNext());
}
cursor.close();
//db1.close();
}
private void initiatePopupWindow() {
try {
Log.e("string_ActivityId ", " = " + string_ActivityId);
dbhelper = new MyDbHelper(this);
SQLiteDatabase db = dbhelper.getReadableDatabase();
Cursor cursor1 = db.rawQuery("select * from ALL_Post where ActivityId " + "= ? ", new String[]{string_ActivityId});
if (cursor1.moveToFirst()) {
struserId1 = cursor1.getString(cursor1.getColumnIndex("UserId"));
strobjectId1 = cursor1.getString(cursor1.getColumnIndex("VesselId"));
Log.e("initiatePopupWindow ", "onCameraclick strobjectId1 = " + strobjectId1);
Log.e("initiatePopupWindow ", "onCameraclickt struserId1 = " + struserId1);
}
cursor1.close();
db.close();
LayoutInflater inflater = (LayoutInflater) AllPosts_Page.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.camera_popup, (ViewGroup) findViewById(R.id.popup_element));
pwindo = new PopupWindow(layout, 600, 380, true);
pwindo.showAtLocation(layout, Gravity.BOTTOM, 0, 0);
pwindo.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
btnCamera = (Button) layout.findViewById(R.id.button_Camera);
btnCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
btnGallery = (Button) layout.findViewById(R.id.button_Gallery);
btnGallery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
}
});
cancelPopUp = (Button) layout.findViewById(R.id.btnCancelCamera);
cancelPopUp.setOnClickListener(cancel_button_click_listener);
} catch (Exception e) {
e.printStackTrace();
}
}
class MyListAdapter extends ArrayAdapter<All_Post> {
Context context;
int layoutResourceId;
/**/
ArrayList<All_Post> data = new ArrayList<All_Post>();
public MyListAdapter(Context context, int layoutResourceId, ArrayList<All_Post> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public int getCount() {
return data.size();
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
final Holder holder;
if (row == null) {
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
row = vi.inflate(R.layout.all_post_row, null);
holder = new Holder();
holder.text_ActivityId = (TextView) row.findViewById(R.id.textActivityId);
holder.text_InspectorName = (TextView) row.findViewById(R.id.textInspectorName);
holder.text_SpChar = (TextView) row.findViewById(R.id.textSpChar);
holder.text_Notation = (TextView) row.findViewById(R.id.textNotation);
holder.txtViewDate = (TextView) row.findViewById(R.id.txt_Date);
holder.txtInitialLetter = (TextView) row.findViewById(R.id.txt_InitialLetter);
holder.txtRemark = (TextView) row.findViewById(R.id.textRemark);
holder.imgBtn_FollowUp = (ImageView) row.findViewById(R.id.imgButton_FoloowUp);
holder.imgBtn_RateEquipMent = (ImageView) row.findViewById(R.id.imgButtonRateEquipment);
holder.imgBtn_Camera = (ImageView) row.findViewById(R.id.imgButton_Camera);
holder.imgBtn_Audio = (ImageView) row.findViewById(R.id.imgButton_RecordAudio);
holder.horizontalScrollView = (HorizontalScrollView) row.findViewById(R.id.hlist);
holder.lLinearLayout = (LinearLayout) row.findViewById(R.id.innerlay);
row.setTag(holder);
} else {
holder = (Holder) row.getTag();
}
final All_Post all_Post = data.get(position);
holder.text_ActivityId.setText(all_Post.getStrActivityId());
holder.text_InspectorName.setText(all_Post.getStringInspectorname());
String typenameRGN = all_Post.getStrShortName();
Log.e("typenameRGN ", " = " + typenameRGN);
holder.txtInitialLetter.setText(typenameRGN);
if (holder.txtInitialLetter.getText().toString().equals("R")) {
holder.txtInitialLetter.setBackgroundResource(R.drawable.red_circle_shape);
}
if (holder.txtInitialLetter.getText().toString().equals("G")) {
holder.txtInitialLetter.setBackgroundResource(R.drawable.green_circle_shape);
}
if (holder.txtInitialLetter.getText().toString().equals("N")) {
holder.txtInitialLetter.setBackgroundResource(R.drawable.blue_circle_shape);
}
holder.txtRemark.setText(all_Post.getStrRemark());
holder.text_Notation.setText(all_Post.getStrNotationNo());
String strtextNotation = holder.text_Notation.getText().toString().trim();
Log.e("strtextNotation ", " = " + strtextNotation);
holder.txtViewDate.setText(all_Post.getActiondate());
strListItem_ActivityId = all_Post.getStrActivityId();
Log.e("strListItem_ActivityId ", " = " + strListItem_ActivityId);
dbhelper = new MyDbHelper(AllPosts_Page.this);
SQLiteDatabase db = dbhelper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from ActivityObjectList where activityId " + "= ? ", new String[]{strListItem_ActivityId});
imageArray.clear();
if (cursor.moveToFirst()) {
do {
String imagePath = cursor.getString(cursor.getColumnIndex("imageaudioPath"));
imageArray.add(imagePath);
}
while (cursor.moveToNext());
}
cursor.close();
//db.close();
//OnClickListener for camera button in the List
holder.imgBtn_Camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
string_ActivityId = all_Post.getStrActivityId();
initiatePopupWindow();
}
});
final String actid = all_Post.getStrActivityId();
dbhelper = new MyDbHelper(context);
db = dbhelper.getReadableDatabase();
Cursor cursor1 = db.rawQuery("select * from ALL_Post where activityId ='" + actid + "'", null);
if (cursor1.moveToFirst()) {
do {
String strStarFlag = cursor1.getString(cursor1.getColumnIndex("StarFlag"));
Log.e("strStarFlag ", " is = " + strStarFlag);
if (strStarFlag.equals("0")) {
holder.imgBtn_RateEquipMent.setImageResource(R.drawable.stargrey_new);
} else if (strStarFlag.equals("1")) {
holder.imgBtn_RateEquipMent.setImageResource(R.drawable.yellow_star);
}
}
while (cursor1.moveToNext());
}
cursor1.close();
db.close();
return row;
}
}
private class GetgetDoenLoaddata extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... arg0) {
getDoenLoaddata();
return null;
}
}
}
这是我的日志
E/SQLITE数据库﹕ close()从未在数据库“/data/data/com”上显式调用。实例塔泽恩。classnkk/databases/classnkk'android。数据库sqlite。DatabaseObjectNotClosedException:应用程序没有关闭在android上打开的游标或数据库对象。数据库sqlite。SQLITE数据库。(SQLiteDatabase.java:1943)在android上。数据库sqlite。SQLITE数据库。android上的openDatabase(SQLiteDatabase.java:1007)。数据库sqlite。SQLITE数据库。android上的openDatabase(SQLiteDatabase.java:986)。数据库sqlite。SQLITE数据库。android上的openOrCreateDatabase(SQLiteDatabase.java:1051)。应用程序。ContextImpl。android上的openOrCreateDatabase(ContextImpl.java:770)。所容纳之物ContextWrapper。android上的openOrCreateDatabase(ContextWrapper.java:221)。数据库sqlite。SQLiteOpenHelper。android上的getWritableDatabase(SQLiteOpenHelper.java:157)。数据库sqlite。SQLiteOpenHelper。getReadableDatabase(SQLiteOpenHelper.java:231)位于com。实例塔泽恩。classnkk。AllPosts\u第$mylistapter页。android上的getView(AllPosts_Page.java:1225)。小装置。AbsListView。android上的获取视图(AbsListView.java:2033)。小装置。ListView。android上的makeAndAddView(ListView.java:1772)。小装置。ListView。android上的fillDown(ListView.java:672)。小装置。ListView。android上的fillGap(ListView.java:636)。小装置。AbsListView。android上的trackMotionScroll(AblistView.java:4546)。小装置。AbsListView$FlingRunnable。在android上运行(AbsListView.java:3813)。操作系统。处理程序。android上的handleCallback(Handler.java:605)。操作系统。处理程序。android上的dispatchMessage(Handler.java:92)。操作系统。活套。android上的loop(Looper.java:137)。应用程序。活动线程。java上的main(ActivityThread.java:4340)。郎。反思。方法java上的InvokEnable(本机方法)。郎。反思。方法在com上调用(Method.java:511)。Android内部的操作系统。Zyhtml" target="_blank">goteInit$MethodandArgscaler。在com上运行(ZygoteInit.java:784)。Android内部的操作系统。合子岩。dalvik的main(ZygoteInit.java:551)。系统国家艺术。主要(本地方法)10-17 10:31:47.927 1242-1251/?电子/系统﹕ 终结器10-17 10:31:47.927 1242-1251/?电子/系统﹕ Java语言lang.IllegalStateException:没有数据库锁!在Android。数据库sqlite。SQLITE数据库。android上的verifyLockOwner(SQLiteDatabase.java:2090)。数据库sqlite。SQLITE数据库$1。android上的entryRemoved(SQLiteDatabase.java:2182)。数据库sqlite。SQLITE数据库$1。android上的entryRemoved(SQLiteDatabase.java:2178)。util。鲁卡奇。android上的trimToSize(LruCache.java:197)。util。鲁卡奇。android上的RejectAll(LruCache.java:285)。数据库sqlite。SQLITE数据库。android上的deallocCachedSqlStatements(SQLiteDatabase.java:2143)。数据库sqlite。SQLITE数据库。android上的closeClosable(SQLiteDatabase.java:1126)。数据库sqlite。SQLITE数据库。在java上完成(SQLiteDatabase.java:1914)。lang.Daemons$FinalizerDaemon。doFinalize(Daemons.java:182)位于java。lang.Daemons$FinalizerDaemon。在java上运行(Daemons.java:168)。lang.Thread。运行(Thread.java:856)
你的logcat抛出了什么:
Android数据库sqlite。DatabaseObjectNotClosedException:应用程序没有关闭在android上打开的游标或数据库对象。数据库sqlite。SQLITE数据库。
无需注释掉db。close()。启用此选项:从未在数据库上显式调用Android error-close()
https://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
因此,在看到您的代码后,我将建议一种不同的方法,即我说您应该在每次调用后关闭()
的第一种方法。
我看到您的代码中存在许多问题,下面是一些建议:
dbhelper=new MyDbHelper(this);
?您应该只在onCreate
SQLiteDatabase db
,然后在onCreate
中执行db=dbhelper.getWritableDatabase();
一次。db.close()
的所有其他调用,除了onDestroy()
方法。dbhelper.getReadableDatabase();
和dbhelper.getWritableDatabase();
的所有调用,因为您已经从onCreate
方法中拥有一个实例db
,您可以在活动中的任何位置使用它所以基本上我想说的是,你只需要在onCreate中获得一次数据库的可写实例,然后在onDestroy中关闭它。
在下面的代码中,连接到sdcard上的数据库,数据库打开,但在logcat中显示错误。 而logcat错误为: 谢谢你帮我。
我使用与已安装的WAMPServer v-3.2.0关联的phpMyAdmin创建了一个MySQL数据库“testdatabase”,但是,当我尝试使用php连接数据库时,如下面代码中所列: 异常getMessage和GetTraceAssString打印以下错误消息: 连接失败:SQLSTATE[HY000][1049]未知数据库“testdatabase”#0 C:\wamp64\www\Te
问题内容: 我有一个由sqlite数据库提供的listview。我在几个不同的点调用fillData()来更新listview。 那行得通…问题是,当我打开/关闭/跳转活动时,logcat中出现错误。它不会使程序崩溃。错误是: 请确保您在游标上显式调用close(), 并且 从未在数据库上显式调用close() 因此,在})下;如果我将mDbHelper.close()放进去,则崩溃,提示数据库未
原关闭原因未解决 我是一个spring批处理初学者,我正在开发一个应用程序,需要根据条件调用两个不同的DB。 该应用程序的作用如下:读取包含信用卡和借记卡号码的平面文件,然后根据号码是信用卡还是借记卡,我必须调用数据库以获取一些信息,然后使用该信息制作csv文件。问题是有两个数据库,一个用于借记卡,另一个用于信用卡。 我的问题是,我很难为DB的条件调用配置批处理作业。如果只有一个数据库可以调用,我
一切正常,但DatabaseReference无法获取数据,这就像是忽略了我的代码运行,就像我的internet无法运行一样,请帮助我,我是这个社区的新手,下面是我的代码和图片。 以前它是工作的,但由于我只是更改了一些代码,使只有currentVersion>=vCode,这样即使数据库中的值是 firebase数据库映像 mainactivity.java manifest.xml 依赖关系
在Angular JS中,很容易在HTML表单中显示类属性的值。 让我们举个例子来了解更多有关数据显示的信息。 在我们的示例中,我们将在HTML页面中查看在类中显示各种属性的值。 Step 1 - 将app.component.ts文件的代码更改为以下内容。 import { Component } from '@angular/core'; @Component ({ selecto