1

这是卡提克。我的应用程序有两件事离线和在线。每当没有网络时,我都会使用离线数据库事务。因此,当我使用在线登录时,我会创建数据库。如果网络关闭,那么在线插入的记录(已交易)我用来离线工作以显示它们并与它们进行交易. 我的问题是能够在 mobile 和 emulator 中以调试模式运行我的应用程序。但是当我在移动端运行应用程序时没有调试,我收到错误要求我关闭应用程序。

这是我的代码。

这是我离线的仪表板...

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.offline_dash_board);
    try {
    mySQLiteAdapter = new MySQLiteHelper(OfflineDashBoard.this);
    mySQLiteAdapter.openToWrite();
    ddEducationalLevels = (Spinner) findViewById(R.id.offLineEduLevel);
    ddRegions = (Spinner) findViewById(R.id.offLineRegions);
    ddDistricts = (Spinner) findViewById(R.id.offLineDistricts);
    listView = (ListView) findViewById(R.id.offlineLstSchools);
    cursorRegions = mySQLiteAdapter.getRegions();
    cursorEduLevels = mySQLiteAdapter.getEducationalLevels();

    mArrayListEducationalLevel = new ArrayList<String>();
    mArrayListRegions = new ArrayList<String>();
    mArrayListDistricts = new ArrayList<String>();
    thread = new Thread(this);
    thread.start();
    }catch(Exception e) {

    }
}

public void run() {

    if (bindLevels == false) {
        try {
            mArrayListEducationalLevel.add("---Select---");
            cursorEduLevels.moveToFirst();
            while (!cursorEduLevels.isAfterLast()) {
                mArrayListEducationalLevel.add(cursorEduLevels
                        .getString(cursorEduLevels
                                .getColumnIndex("txtEducationalLevels")));
                cursorEduLevels.moveToNext();
            }
            aaprovEduLevel = new ArrayAdapter<String>(
                    OfflineDashBoard.this,
                    android.R.layout.simple_spinner_item,
                    mArrayListEducationalLevel);
            aaprovEduLevel
                    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            ddEducationalLevels.setAdapter(aaprovEduLevel);
        } catch (Exception e) {
        }
    }

    // =====================================================
    if (bindRegions == false) {
        try {
            mArrayListRegions.add("---Select---");
            cursorRegions.moveToFirst();
            while (!cursorRegions.isAfterLast()) {
                mArrayListRegions.add(cursorRegions.getString(cursorRegions
                        .getColumnIndex("txtRegion")));
                cursorRegions.moveToNext();
            }
            handler1.sendEmptyMessage(0);

        } catch (Exception e) {
        }
    }
    // ========================================================
    if (bindDistrict == true) {
        try {
            cursorDistricts = mySQLiteAdapter.getDistricts(district);
            mArrayListDistricts.add("---Select---");
            cursorDistricts.moveToFirst();

            while (!cursorDistricts.isAfterLast()) {
                mArrayListDistricts.add(cursorDistricts
                        .getString(cursorDistricts
                                .getColumnIndex("txtDistrictName")));
                cursorDistricts.moveToNext();
            }
            handler2.sendEmptyMessage(0);

        }

        catch (Exception e) {

        }
    }
    if (bindSchools == false) {
        try {
            String txtDistrictName = ddDistricts.getSelectedItem()
                    .toString();
            // ArrayList<String> catalogueData=new ArrayList<String>();
            cursorSchools = mySQLiteAdapter.getSchools(txtDistrictName);

            handler3.sendEmptyMessage(0);

        }

        catch (Exception ex) {

        }

    }
}

private Handler handler1 = new Handler() {

    @Override
    public void handleMessage(Message msg) {

        ArrayAdapter<String> aaprov;
        try {
            aaprovRegions = new ArrayAdapter<String>(OfflineDashBoard.this,
                    android.R.layout.simple_spinner_item, mArrayListRegions);
            aaprovRegions
                    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            ddRegions.setAdapter(aaprovRegions);
            ddRegions.setOnItemSelectedListener(selectDistrictListener);
        } catch (Exception e) {

        }

    }
};
private Handler handler2 = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        ArrayAdapter<String> aaprov;
        try {
            aaprovDistricts = new ArrayAdapter<String>(
                    OfflineDashBoard.this,
                    android.R.layout.simple_spinner_item,
                    mArrayListDistricts);
            aaprovDistricts
                    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            ddDistricts.setAdapter(aaprovDistricts);
            ddDistricts.setOnItemSelectedListener(selectSchoolListener);
        } catch (Exception e) {

        }

    }
};
private Handler handler3 = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        try {
            SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(
                    OfflineDashBoard.this, R.layout.row, cursorSchools,
                    new String[] { "_id", "txtSchoolName" }, new int[] {
                            R.id.name_entry, R.id.number_entry });
            listView.setAdapter(mAdapter);
            listView.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    Cursor cur = (Cursor) parent
                            .getItemAtPosition(position);
                    String SchoolCode = cur.getString(cur
                            .getColumnIndex("_id"));
                    String SchoolName = cur.getString(cur
                            .getColumnIndex("txtSchoolName"));
                    Intent view_school = new Intent(OfflineDashBoard.this,
                            OfflineViewSchool.class);
                    Bundle b = new Bundle();
                    b.putString("EducationalLevel", ddEducationalLevels
                            .getSelectedItem().toString());
                    b.putString("Region", ddRegions.getSelectedItem()
                            .toString());
                    b.putString("District", ddDistricts.getSelectedItem()
                            .toString());
                    b.putString("SchoolName", SchoolName);
                    b.putString("SchoolCode", SchoolCode);
                    view_school.putExtras(b);
                    startActivity(view_school);
                }
            });
        } catch (Exception e) {

        }
    }
};

private OnItemSelectedListener selectDistrictListener = new OnItemSelectedListener() {

    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
        // TODO Auto-generated method stub
        district = arg0.getSelectedItem().toString();
        if (district != "---Select---") {
            // Toast.makeText(getApplicationContext(), district,
            // Toast.LENGTH_SHORT).show();
            bindLevels = true;
            bindRegions = true;
            bindDistrict = true;
            // bindSchools=false;
            thread = new Thread(OfflineDashBoard.this);
            thread.start();
        }
    }

    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }
};
private OnItemSelectedListener selectSchoolListener = new OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {

        school = arg0.getSelectedItem().toString();
        if (school != "---Select---") {
            bindLevels = true;
            bindRegions = true;
            bindDistrict = false;
            bindSchools = false;
            thread = new Thread(OfflineDashBoard.this);
            thread.start();
        }

    }

    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }

};




public boolean onKeyDown(int keyCode, KeyEvent event)  {
    if (  Integer.valueOf(android.os.Build.VERSION.SDK) < 7 //Instead use android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
            && keyCode == KeyEvent.KEYCODE_BACK
            && event.getRepeatCount() == 0) {
        // Take care of calling this method on earlier versions of
        // the platform where it doesn't exist.
        onBackPressed();
    }

    return super.onKeyDown(keyCode, event);
}
@Override
public void onBackPressed() {
      // This will be called either automatically for you on 2.0
    // or later, or by the code above on earlier versions of the
    // platform.
    mySQLiteAdapter.close();
   this.finish();
    return;
}

public boolean onCreateOptionsMenu(Menu menu) {

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu1, menu);
    //
    // MenuItem itemaddSchool =(MenuItem)menu.findItem(R.id.addSchool);
    // itemaddSchool.setTitle("Add School");
    // itemaddSchool.setIcon(R.drawable.classroom);
    //
    MenuItem item = (MenuItem) menu.findItem(R.id.exit1);
    // item.setVisible(false);
    item.setTitle("Map View");
    item.setIcon(R.drawable.map1);
    item.setVisible(false);
    // ===================//
    MenuItem itemAddSchool = (MenuItem) menu.findItem(R.id.addSchool);
    itemAddSchool.setTitle("Add School");
    itemAddSchool.setIcon(R.drawable.school);
    itemAddSchool.setVisible(false);
    // =================//

    MenuItem item1 = (MenuItem) menu.findItem(R.id.school);
    item1.setVisible(false);
    item1.setIcon(R.drawable.school);



    MenuItem item2 = (MenuItem) menu.findItem(R.id.homepage);
    item2.setIcon(R.drawable.addhome);
    item2.setVisible(false);

    MenuItem item5 = (MenuItem) menu.findItem(R.id.addTeacher);
    item5.setIcon(R.drawable.newteacher);
    item5.setVisible(false);

    MenuItem item6 = (MenuItem) menu.findItem(R.id.Logout1);
    item6.setIcon(R.drawable.logout);

    MenuItem iteminfra = (MenuItem) menu.findItem(R.id.schInfra);
    iteminfra.setIcon(R.drawable.classroom);
    iteminfra.setVisible(false);

    MenuItem itemstud = (MenuItem) menu.findItem(R.id.studEnrollment);
    itemstud.setIcon(R.drawable.student);
   itemstud.setVisible(false);

    MenuItem itemstaff = (MenuItem) menu.findItem(R.id.staffEnrollment);
    itemstaff.setIcon(R.drawable.teacherenroll);
    itemstaff.setVisible(false);

    MenuItem itemrpt = (MenuItem) menu.findItem(R.id.rpt);
    itemrpt.setVisible(false);
    return true;

}
public boolean onOptionsItemSelected(MenuItem item) {

    Intent myIntent;
    Bundle b = new Bundle();
    switch (item.getItemId()) {
    case R.id.Logout1:
        ((MyApplication) OfflineDashBoard.this.getApplication()).setusername("");
        ((MyApplication) OfflineDashBoard.this.getApplication()).setpassword("");
    //  mySQLiteAdapter.close();
        myIntent = new Intent(this.getApplicationContext(), Login.class);
        myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivityForResult(myIntent, 0);
        this.finish();
        return true;  
    }

    return true;

}

}

这是我的原木猫KIRAN

11-29 09:02:32.542: D/dalvikvm(17303): GC_EXTERNAL_ALLOC freed 82K, 48% free 2806K/5379K, external 0K/0K, paused 38ms
11-29 09:02:32.592: D/ATRecorder(17303): com.htc.autotest.dlib.RecordEngine in loader dalvik.system.DexClassLoader@40513918
11-29 09:02:42.512: D/Database(17303): dbopen(): path = /data/data/Com.SEMISliteUganda/databases/offlineEMISLITE, flag = 6, file size = 23552
11-29 09:02:42.522: D/dalvikvm(17303): GC_CONCURRENT freed 152K, 47% free 3028K/5639K, external 405K/917K, paused 2ms+4ms
11-29 09:02:42.562: I/Database(17303): sqlite returned: error code = 0, msg = Recovered 19 frames from WAL file /data/data/Com.SEMISliteUganda/databases/offlineEMISLITE-wal
11-29 09:02:42.562: D/Database(17303): dbopen(): path = /data/data/Com.SEMISliteUganda/databases/offlineEMISLITE, mode: wal, disk free size: 1063 M, handle: 0x3d11f0
11-29 09:02:47.917: D/dalvikvm(17303): GC_CONCURRENT freed 310K, 47% free 3166K/5959K, external 405K/917K, paused 3ms+2ms
11-29 09:02:48.848: D/dalvikvm(17303): GC_CONCURRENT freed 445K, 49% free 3146K/6087K, external 405K/917K, paused 2ms+1ms
11-29 09:02:51.751: D/dalvikvm(17303): GC_CONCURRENT freed 542K, 50% free 3082K/6087K, external 405K/917K, paused 4ms+6ms
11-29 09:02:57.877: D/dalvikvm(17303): GC_CONCURRENT freed 361K, 48% free 3191K/6087K, external 405K/917K, paused 2ms+5ms
11-29 09:03:03.632: D/dalvikvm(17303): GC_FOR_MALLOC freed 184K, 46% free 3330K/6151K, external 405K/917K, paused 45ms
11-29 09:03:03.903: D/dalvikvm(17303): GC_CONCURRENT freed 412K, 46% free 3391K/6279K, external 405K/917K, paused 2ms+2ms
11-29 09:03:06.645: W/KeyCharacterMap(17303): Can't open keycharmap file
11-29 09:03:06.645: W/KeyCharacterMap(17303): Error loading keycharmap file '/system/usr/keychars/cy8c-touchscreen.kcm.bin'. hw.keyboards.65538.devname='cy8c-touchscreen'
11-29 09:03:06.655: I/KeyCharacterMap(17303): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
11-29 09:03:06.926: D/dalvikvm(17303): GC_CONCURRENT freed 479K, 48% free 3313K/6279K, external 405K/917K, paused 5ms+2ms
11-29 09:03:13.202: D/Database(17303): dbopen(): path = /data/data/Com.SEMISliteUganda/databases/offlineEMISLITE, flag = 6, file size = 15360
11-29 09:03:13.202: D/Database(17303): dbopen(): path = /data/data/Com.SEMISliteUganda/databases/offlineEMISLITE, mode: wal, disk free size: 1062 M, handle: 0x422f58
11-29 09:03:21.069: W/KeyCharacterMap(17303): Can't open keycharmap file
11-29 09:03:21.069: W/KeyCharacterMap(17303): Error loading keycharmap file '/system/usr/keychars/cy8c-touchscreen.kcm.bin'. hw.keyboards.65538.devname='cy8c-touchscreen'
11-29 09:03:21.069: I/KeyCharacterMap(17303): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
11-29 09:03:25.764: D/Database(17303): dbopen(): path = /data/data/Com.SEMISliteUganda/databases/offlineEMISLITE, flag = 6, file size = 15360
11-29 09:03:25.764: D/Database(17303): dbopen(): path = /data/data/Com.SEMISliteUganda/databases/offlineEMISLITE, mode: wal, disk free size: 1062 M, handle: 0x4a44a0
11-29 09:03:32.841: D/dalvikvm(17303): GC_CONCURRENT freed 155K, 44% free 3549K/6279K, external 810K/917K, paused 2ms+5ms
11-29 09:03:32.871: E/Database(17303): close() was never explicitly called on database '/data/data/Com.SEMISliteUganda/databases/offlineEMISLITE' 
11-29 09:03:32.871: E/Database(17303): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
11-29 09:03:32.871: E/Database(17303):  at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1954)
11-29 09:03:32.871: E/Database(17303):  at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:902)
11-29 09:03:32.871: E/Database(17303):  at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:936)
11-29 09:03:32.871: E/Database(17303):  at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:929)
11-29 09:03:32.871: E/Database(17303):  at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:601)
11-29 09:03:32.871: E/Database(17303):  at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
11-29 09:03:32.871: E/Database(17303):  at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
11-29 09:03:32.871: E/Database(17303):  at Com.SEMISliteUganda.MySQLiteHelper.openToWrite(MySQLiteHelper.java:56)
11-29 09:03:32.871: E/Database(17303):  at Com.SEMISliteUganda.OfflineDashBoard.onCreate(OfflineDashBoard.java:64)
11-29 09:03:32.871: E/Database(17303):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
11-29 09:03:32.871: E/Database(17303):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794)
11-29 09:03:32.871: E/Database(17303):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
11-29 09:03:32.871: E/Database(17303):  at android.app.ActivityThread.access$1500(ActivityThread.java:132)
11-29 09:03:32.871: E/Database(17303):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
11-29 09:03:32.871: E/Database(17303):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-29 09:03:32.871: E/Database(17303):  at android.os.Looper.loop(Looper.java:143)
11-29 09:03:32.871: E/Database(17303):  at android.app.ActivityThread.main(ActivityThread.java:4293)
11-29 09:03:32.871: E/Database(17303):  at java.lang.reflect.Method.invokeNative(Native Method)
11-29 09:03:32.871: E/Database(17303):  at java.lang.reflect.Method.invoke(Method.java:507)
11-29 09:03:32.871: E/Database(17303):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-29 09:03:32.871: E/Database(17303):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-29 09:03:32.871: E/Database(17303):  at dalvik.system.NativeStart.main(Native Method)
11-29 09:03:32.871: D/Database(17303): dbclose(): path = /data/data/Com.SEMISliteUganda/databases/offlineEMISLITE, handle = 0x422f58
11-29 09:03:32.881: E/Database(17303): close() was never explicitly called on database '/data/data/Com.SEMISliteUganda/databases/offlineEMISLITE' 
11-29 09:03:32.881: E/Database(17303): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
11-29 09:03:32.881: E/Database(17303):  at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1954)
11-29 09:03:32.881: E/Database(17303):  at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:902)
11-29 09:03:32.881: E/Database(17303):  at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:936)
11-29 09:03:32.881: E/Database(17303):  at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:929)
11-29 09:03:32.881: E/Database(17303):  at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:601)
11-29 09:03:32.881: E/Database(17303):  at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
11-29 09:03:32.881: E/Database(17303):  at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
11-29 09:03:32.881: E/Database(17303):  at Com.SEMISliteUganda.MySQLiteHelper.openToWrite(MySQLiteHelper.java:56)
11-29 09:03:32.881: E/Database(17303):  at Com.SEMISliteUganda.home1.onCreate(home1.java:127)
11-29 09:03:32.881: E/Database(17303):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
11-29 09:03:32.881: E/Database(17303):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794)
11-29 09:03:32.881: E/Database(17303):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
11-29 09:03:32.881: E/Database(17303):  at android.app.ActivityThread.access$1500(ActivityThread.java:132)
11-29 09:03:32.881: E/Database(17303):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
11-29 09:03:32.881: E/Database(17303):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-29 09:03:32.881: E/Database(17303):  at android.os.Looper.loop(Looper.java:143)
11-29 09:03:32.881: E/Database(17303):  at android.app.ActivityThread.main(ActivityThread.java:4293)
11-29 09:03:32.881: E/Database(17303):  at java.lang.reflect.Method.invokeNative(Native Method)
11-29 09:03:32.881: E/Database(17303):  at java.lang.reflect.Method.invoke(Method.java:507)
11-29 09:03:32.881: E/Database(17303):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-29 09:03:32.881: E/Database(17303):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-29 09:03:32.881: E/Database(17303):  at dalvik.system.NativeStart.main(Native Method)
11-29 09:03:32.881: D/Database(17303): dbclose(): path = /data/data/Com.SEMISliteUganda/databases/offlineEMISLITE, handle = 0x3d11f0
11-29 09:03:38.887: D/Database(17303): dbopen(): path = /data/data/Com.SEMISliteUganda/databases/offlineEMISLITE, flag = 6, file size = 15360
11-29 09:03:38.887: D/Database(17303): dbopen(): path = /data/data/Com.SEMISliteUganda/databases/offlineEMISLITE, mode: wal, disk free size: 1062 M, handle: 0x3a2ad0
11-29 09:03:47.175: W/KeyCharacterMap(17303): Can't open keycharmap file
11-29 09:03:47.175: W/KeyCharacterMap(17303): Error loading keycharmap file '/system/usr/keychars/cy8c-touchscreen.kcm.bin'. hw.keyboards.65538.devname='cy8c-touchscreen'
11-29 09:03:47.175: I/KeyCharacterMap(17303): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
4

1 回答 1

0

LogCat 说:

close() was never explicitly called on database 

当您完成数据库调用以关闭它时,我在您提供的代码SQLiteDatabase.close()中看不到它。SQLiteDatabase.close().

见这篇文章

于 2012-11-29T05:04:01.177 回答