1

我正在使用 python 脚本运行一些计算并将结果保存到 SQLite 数据库。Python 操作需要时间来处理,所以我把这部分放在 asyncTask 中。并且数据库插入写在 onPostExecute() 方法中。数据插入正在发生并返回行 ID。这些数据显示在另一个活动中,而我试图打开该记录屏幕应用程序崩溃并且该 db 数据行也从 db 发出警告。我通过删除那个 python 部分来尝试这个,它工作正常。我也可以看到记录列表。

请参阅下面的完整错误日志

    2020-11-25 21:03:35.602 3997-3997/com.ust.step_count_directions E/SQLiteLog: (522) statement aborts at 2: [select * from GaitStatisticsDatas WHERE Category = 0] disk I/O error - SQLITE_IOERR_SHORT_READ
2020-11-25 21:03:35.602 3997-3997/com.ust.step_count_directions E/SQLiteQuery: exception: disk I/O error - SQLITE_IOERR_SHORT_READ (Sqlite code 522 SQLITE_IOERR_SHORT_READ), (OS error - 11:Try again); query: select * from GaitStatisticsDatas WHERE Category = 0
2020-11-25 21:03:35.603 3997-3997/com.ust.step_count_directions D/AndroidRuntime: Shutting down VM
2020-11-25 21:03:35.607 3997-3997/com.ust.step_count_directions E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ust.step_count_directions, PID: 3997
    android.database.sqlite.SQLiteDiskIOException: disk I/O error - SQLITE_IOERR_SHORT_READ (Sqlite code 522 SQLITE_IOERR_SHORT_READ), (OS error - 11:Try again)
        at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method)
        at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:904)
        at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:851)
        at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
        at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:149)
        at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:137)
        at com.ust.step_count_directions.acitvities.ui.home.RecordList.onCreateView(RecordList.java:140)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2698)
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:320)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
        at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
        at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2169)
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1992)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1947)
        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
        at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
        at android.os.Handler.handleCallback(Handler.java:907)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7625)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
    

看我的代码

class BackgroundRunner extends AsyncTask<String,String,String>{
        ProgressDialog progressDialog;

        @Override
        protected void onPreExecute() {
            progressDialog = new ProgressDialog(TestScreen.this, R.style.MyTheme);
            progressDialog.setCancelable(false);
            progressDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Large);
            progressDialog.show();
            super.onPreExecute();
        }

        @Override
        protected String doInBackground(String... strings) {
            PyObject pyObject1 = null;
            Log.d("array_time..","array_time.."+mStartTestTime+" "+endTestTime);

            if (!Python.isStarted()) {
                Log.d("Py..", "Py..");

                Python.start(new AndroidPlatform(mcontext));

           
            Python py = Python.getInstance();
            PyObject pyObject = py.getModule("app");
            pyObject1 = pyObject.callAttr("score", mStartTestTime, endTestTime);

            p_step_count = pyObject1.asList().get(0).toInt();
            p_total_time = pyObject1.asList().get(1).toDouble();
            p_stride_time = pyObject1.asList().get(2).toDouble();
            p_stance_time = pyObject1.asList().get(3).toDouble();
            p_swing_time = pyObject1.asList().get(4).toDouble();
            p_cadence = pyObject1.asList().get(5).toDouble();
            p_gait_score = pyObject1.asList().get(6).toDouble();
            }
            return "null";
        }

        @Override
        protected void onPostExecute(String s) {

     dbManager.insertStatistics2("s",helper.TABLE_STEP_STATISTICS,p_stride_time,p_cadence,
                p_stance_time, p_swing_time,p_total_time,Category,p_step_count,p_gait_score);

 progressDialog.dismiss();

            mAlertDialogView = ViewUtils.showResultDialog(TestScreen.this, strideTime, stanceTime, swingTime, cadenceTime, totalSteps, totalTime, view -> {
                if (mAlertDialogView != null) {
                    mAlertDialogView.dismiss();
                    resetTimer();
                    crpv.setPercent(0);
                    static_img.setVisibility(View.VISIBLE);
                    static_img.setImageResource(R.drawable.walk_static);
                    gifImageView.setVisibility(View.GONE);
                    test_t2.setText(discription);
                    test_t1.setText(heading);
                  

                }
            });

        }
    }

并且错误是在下面的代码上的 cursor.getCount() > 0 上抛出的,这是另一个片段。

  helper = new DatabaseHelper(getContext());
        dbManager = new DBManager(getContext());
        dbManager.open();
      Cursor cursor = dbManager.fetchNormal();
            if (cursor.getCount() > 0) {
                cursor.moveToFirst();
                while (cursor.isAfterLast() == false) {
                    gait_cycle.add(cursor.getString(cursor.getColumnIndex(helper.COLUMN_CADENCE)));
                    stride_time.add(cursor.getString(cursor.getColumnIndex(helper.COLUMN_STRIDE_TIME)));
                    stance_time.add(cursor.getString(cursor.getColumnIndex(helper.COLUMN_STANCE_TIME)));
                    cursor.moveToNext();
    
                }
    
            }
4

0 回答 0