4

我收到一个No implementation found for native Ldalvik/system/VMRuntime;.pauseGc错误,下面是 logCat。

05-13 22:39:22.538: W/dalvikvm(8350): No implementation found for native Ldalvik/system/VMRuntime;.pauseGc:(Ljava/lang/String;)I
05-13 22:39:22.543: E/MyThread(8350): Pause GC
05-13 22:39:22.543: E/MyThread(8350): java.lang.reflect.InvocationTargetException
05-13 22:39:22.543: E/MyThread(8350): at java.lang.reflect.Method.invokeNative(Native Method)
05-13 22:39:22.543: E/MyThread(8350): at java.lang.reflect.Method.invoke(Method.java:515)
05-13 22:39:22.543: E/MyThread(8350): at android.app.MyThread.pauseGC(MyThread.java:5525)
05-13 22:39:22.543: E/MyThread(8350): at android.app.MyThread.performLaunchActivity(MyThread.java:2324)
05-13 22:39:22.543: E/MyThread(8350): at android.app.MyThread.handleLaunchActivity(MyThread.java:2471)
05-13 22:39:22.543: E/MyThread(8350): at android.app.MyThread.access$900(MyThread.java:175)
05-13 22:39:22.543: E/MyThread(8350): at android.app.MyThread$H.handleMessage(MyThread.java:1308)
05-13 22:39:22.543: E/MyThread(8350): at android.os.Handler.dispatchMessage(Handler.java:102)
05-13 22:39:22.543: E/MyThread(8350): at android.os.Looper.loop(Looper.java:146)
05-13 22:39:22.543: E/MyThread(8350): at android.app.MyThread.main(MyThread.java:5602)
05-13 22:39:22.543: E/MyThread(8350): at java.lang.reflect.Method.invokeNative(Native Method)
05-13 22:39:22.543: E/MyThread(8350): at java.lang.reflect.Method.invoke(Method.java:515)
05-13 22:39:22.543: E/MyThread(8350): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
05-13 22:39:22.543: E/MyThread(8350): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
05-13 22:39:22.543: E/MyThread(8350): at dalvik.system.NativeStart.main(Native Method)
05-13 22:39:22.543: E/MyThread(8350): Caused by: java.lang.UnsatisfiedLinkError: Native method not found: dalvik.system.VMRuntime.pauseGc:(Ljava/lang/String;)I
05-13 22:39:22.543: E/MyThread(8350): at dalvik.system.VMRuntime.pauseGc(Native Method)
05-13 22:39:22.543: E/MyThread(8350): ... 15 more

我搜索了各种论坛,但这个错误与三星 4.4.2 及更高版本的笔记设备子集的更新有关(我有两个具有相同规格的笔记设备,这个错误只发生在其中一个上)

这里的想法是知道究竟是什么导致了这个错误,这样我就可以改变我的程序的过程以避免发生这个错误的情况。一个可信的或官方的答案是最受追捧的,一旦我获得资格,我将在这个问题上悬赏 200。

在我的情况下,当我执行内存密集型操作时会发生这种情况,我的知识(尽管可能很天真)告诉我它与暂停 GC 有关,(manual)调用 System.gc 会为我解决问题吗?

如何从这个错误中恢复?在我的循环中,我一个接一个地从一个数据库表、地址簿和一个文件中读取。这些读取值经过计算过程,结果存储在更大的数据库中。这些语句在一个while循环中,我已经在try catch中进行了检查,以便如果any and not limited to发生此错误。我使用 catch 子句中的 continue 语句从循环的下一次迭代开始——忽略发生崩溃的记录。但是,使用此方法不能保证执行,因为崩溃可能会不断发生,迫使后续记录被忽略。

编辑:这是代码的罪魁祸首:

if(FLAG ==1){
    toRead=new File(getApplicationContext().getFilesDir()+"/Reminders/fileone.txt");
}else{
    toRead=new File(getApplicationContext().getFilesDir()+"/Reminders/output.txt");
}

//  copyDirectoryOneLocationToAnotherLocation(new File(getApplicationContext().getFilesDir()+"/Reminders/output.txt"), new File("mnt/sdcard/filecheck.txt"));


FileInputStream fis=new FileInputStream(toRead);
Scanner sc=new Scanner(fis);

String currentLine;
while(sc.hasNextLine()){
    try{
        System.out.println("count in file"+i);

        currentLine=sc.nextLine();
        // TODO = gets concatnated 
        StringTokenizer st=new StringTokenizer(currentLine,"=",false);
        CONTACT_NAME = toTitleCase(st.nextToken());


        if(CONTACT_NAME.contains("'")){
            CONTACT_NAME = CONTACT_NAME.replace("'", "");
        }
        // *********
        String listStr = st.nextToken();
        String cut = listStr.substring(1, listStr.length() - 1);
        String[] array = cut.split(",");

        //      System.out.println("Array is: "+Arrays.toString(array));


        CONTACT_ID = (array[0].trim());
        String dateStr = (array[1].trim());
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = format.parse(dateStr);
        java.sql.Date dx = new java.sql.Date(date.getTime());
        Date key = dx;
        dateToInsert = String.valueOf(dx); 

        CONTACT_IMAGE_URI = (array[2].trim());
        if(CONTACT_IMAGE_URI.contains("?typ")){
            CONTACT_IMAGE_URI = CONTACT_IMAGE_URI+"e=normal"; 
        }
        if (isCancelled()) {
            break;
        }
        progress = ("" + Character.toUpperCase(CONTACT_NAME.charAt(0)) + CONTACT_NAME.substring(1) + "\n"+i + " of " + lines + " Contacts"); // Progress displayed here. 
        years = getDiffYear(key);               // For years elapsed
        secon = seconds(key);                   // for seconds elapsed
        min = seconds(key) / 60;                // For minutes elapsed
        hours = getDiffHour(key);// For hours elapsed
        mon = months(String.valueOf(key));      // for months elapsed
        days = daysElapsed(key);                // Days elapsed
        weeks = daysElapsed(key) / 7;           // For weeks

        //===============================================================================================================
        if (dateToInsert.contains("0001-") == true){ //Special Case, we added 0001 to Birthdays Which Have NO Year field. 
            //===========================================================================================================

            dbHelper.insert(dateToInsert, CONTACT_NAME, "","", CONTACT_IMAGE_URI, "", "", "", CONTACT_ID, "", "","1"); // All other fields will be empty, because we don't have a Year. 
            int PRIMARY_ID = dbHelper.getPrimaryId();
            String FOREIGN_KEY = dbHelper.getHighestID(PRIMARY_ID); 


            //=====================================================================================================
            //In this case we are only interested in fetching the year alert for next birthday of this contact -->
            //=====================================================================================================

            intCal.yearsToNotify(years, dateToInsert); 
            int yearsSpecial = intCal.getYearsRegular();
            Date dateYearsReg = intCal.getYearsRegDate();

            dbHelper.insertNotifications(5, convertDate(dateYearsReg), 0, yearsSpecial,FOREIGN_KEY,PRIMARY_ID,CONTACT_IMAGE_URI,dateToInsert ); 

        }
        //=========================================================================
        //Case when all the Date fields exist and we set up notifications  --->
        //=========================================================================
        else if(dateToInsert != "null" && dateToInsert.contains("0001-") != true){
            dbHelper.insert(dateToInsert, CONTACT_NAME, String.valueOf(days), String.valueOf(hours), CONTACT_IMAGE_URI, String.valueOf(min),String.valueOf(mon), String.valueOf(secon), CONTACT_ID, String.valueOf(weeks), String.valueOf(years),"1");
            int PRIMARY_ID = dbHelper.getPrimaryId(); // Fetch the PrimaryId (_id) of the above inserted row, its the Foreign key for Notification and SpecialNotifications Table. 
            String FOREIGN_KEY = dbHelper.getHighestID(PRIMARY_ID); // Same as above, but fetches the Name field of the last inserted row. 



            //=========================================================================
            //**Database Insertions Notifications Table/ SpecialNotifications Table**
            //=========================================================================



            //=======================================================================================//
            //Regular intervals DB Insertions: 
            //======================================================================================//
            //Notification Types:
            //1 for months
            //2 for weeks
            //3 for days
            //4 for minutes
            //5 for years
            //6 for seconds
            //7 for hours
            //======================================================================================//

            //==============================
            //For Months 
            //==============================
            intCal.monthsNotify(mon, dateToInsert);
            int monSpecial =  intCal.getMonthRegular(); 
            Date dateMonReg = intCal.getMonRegDate(); 


            dbHelper.insertNotifications(1, convertDate(dateMonReg), 0, monSpecial,FOREIGN_KEY,PRIMARY_ID,CONTACT_IMAGE_URI,dateToInsert );


            //===============================
            //For Weeks 
            //===============================
            intCal.weeksToNotify(weeks,dateToInsert); 
            int weekSpecial = intCal.getWeekRegular();
            Date dateWeekReg =intCal.getWeekRegDate(); 

            dbHelper.insertNotifications(2, convertDate(dateWeekReg), 0, weekSpecial,FOREIGN_KEY,PRIMARY_ID,CONTACT_IMAGE_URI,dateToInsert );


            //===============================
            //For Days
            //===============================
            intCal.daysToNotify(days, dateToInsert); 
            int daysSpecial= intCal.getDaysRegular();  
            Date dateDaysReg = intCal.getDaysRegDate(); 
            dbHelper.insertNotifications(3, convertDate(dateDaysReg), 0, daysSpecial,FOREIGN_KEY,PRIMARY_ID,CONTACT_IMAGE_URI,dateToInsert );


            //===============================
            //For minutes
            //===============================
            intCal.minutesToNotify(min,dateToInsert);
            long minutesSpecial= intCal.getMinutesRegular();
            Date dateMinsReg = intCal.getMinutesRegDate(); 
            dbHelper.insertNotifications(4, convertDate(dateMinsReg), 0,(int) minutesSpecial,FOREIGN_KEY,PRIMARY_ID,CONTACT_IMAGE_URI,dateToInsert );
            //==============================
            //For Years
            //==============================
            intCal.yearsToNotify(years, dateToInsert); 
            int yearsSpecial = intCal.getYearsRegular();
            Date dateYearsReg = intCal.getYearsRegDate();
            dbHelper.insertNotifications(5, convertDate(dateYearsReg), 0, yearsSpecial,FOREIGN_KEY,PRIMARY_ID,CONTACT_IMAGE_URI,dateToInsert );
            //=============================
            //For Seconds
            //=============================
            intCal.secondsToNotify(secon, dateToInsert);
            long secondsSpecial= intCal.getSecondsRegular(); 
            Date dateSecondsReg = intCal.getSecondsRegDate(); 
            dbHelper.insertNotifications(6, convertDate(dateSecondsReg), 0, secondsSpecial,FOREIGN_KEY,PRIMARY_ID,CONTACT_IMAGE_URI,dateToInsert );


            //=============================
            //For Hours
            //=============================
            intCal.hoursToNotify(hours, dateToInsert); 
            int hoursSpecial= intCal.getHoursRegular();
            Date dateHoursReg= intCal.getHoursRegDate(); 
            dbHelper.insertNotifications(7, convertDate(dateHoursReg), 0, hoursSpecial,FOREIGN_KEY,PRIMARY_ID,CONTACT_IMAGE_URI,dateToInsert );



            //============================================================================================//
            //Special Intervals
            //============================================================================================//
            //Notification Types:
            //1 for months
            //2 for weeks
            //3 for days
            //4 for minutes
            //5 for years
            //6 for seconds
            //7 for hours
            //For Years


            intCal.specialIntervalYears(years, dateToInsert); 
            int yearsOnceSpecial =intCal.getYearsSpecial();
            Date dateYearsSpecial = intCal.getYearsSpDate(); 
            dbHelper.insertSpecialNotifications(5, convertDate(dateYearsSpecial), yearsOnceSpecial,FOREIGN_KEY,PRIMARY_ID);


            //For Months
            intCal.specialIntervalMonths(mon,dateToInsert); 
            int monthsOnceSpecial= intCal.getMonthsSpecial();
            Date dateMonthsSpecial = intCal.getMonthsSpDate();
            dbHelper.insertSpecialNotifications(1, convertDate(dateMonthsSpecial), monthsOnceSpecial,FOREIGN_KEY,PRIMARY_ID);


            //For Weeks
            intCal.specialIntervalsWeeks(weeks,dateToInsert); 
            int weeksOnceSpecial= intCal.getWeeksSpecial(); 
            Date dateWeeksSpecial = intCal.getWeeksSpDate(); 
            dbHelper.insertSpecialNotifications(2, convertDate(dateWeeksSpecial), weeksOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

            //For Days
            intCal.specialIntervalsDays(days, dateToInsert); 
            int daysOnceSpecial= intCal.getDaysSpecial(); 
            Date dateDaysSpecial = intCal.getDaysSpDate(); 
            dbHelper.insertSpecialNotifications(3, convertDate(dateDaysSpecial), daysOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

            //For Hours
            intCal.specialIntervalsHours(hours,dateToInsert); 
            int hoursOnceSpecial= intCal.getHoursSpecial();  
            Date dateHoursSpecial = intCal.getHoursSpDate(); 
            dbHelper.insertSpecialNotifications(7, convertDate(dateHoursSpecial), hoursOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

            //For Minutes
            intCal.specialIntervalMinutes(min,dateToInsert); 
            long minutesOnceSpecial= intCal.getMinutesSpecial(); 
            Date dateMinutesSpecial= intCal.getMinutesSpDate(); 
            dbHelper.insertSpecialNotifications(4, convertDate(dateMinutesSpecial), (int)minutesOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

            //For Seconds
            intCal.specialIntervalsSeconds(secon,dateToInsert); 
            long secondsOnceSpecial= intCal.getSecondsSpecial(); 
            Date dateSecondsSpecial= intCal.getSecondsSpDate(); 
            dbHelper.insertSpecialNotifications(6, convertDate(dateSecondsSpecial), secondsOnceSpecial,FOREIGN_KEY,PRIMARY_ID); 
        }

        publishProgress(progress);
        Asycdialog.setMax(lines);
        Asycdialog.incrementProgressBy(1);
        i++;
    }catch (Exception e){
        System.out.println("From catch 4"+e);
        continue; 
    }
}

编辑2:

我正在尝试捕获中执行上述过程,其中我正在使用事务来加快速度。我在 try 块的开头实现了这些事务片段,在那里我开始事务并在 finally 块结束它们并将它们设置在同一个地方成功。

4

2 回答 2

3

这似乎是三星特有的错误。据报道,

到目前为止,除了更新您的 Android 版本(如果我没看错的话)似乎没有其他解决方案。

于 2014-12-08T08:37:36.697 回答
2

我建议更改dbHelper.insert要在事务中完成的操作,这可能会解决这个问题。

尽管您的代码运行速度非常慢且占用大量内存,但它可能会直接导致现有错误或仅在“压力”设备中发生。

当您以这种方式将数据插入 SQLite 时

 private void execQuery(String tableName,ContentValues val)
 {
    sqliteDb = instance.getWritableDatabase();       
    sqliteDb.insert(tableName, null, val);
    return true;
 }

android 方法.insert执行大量安全检查,然后插入它们。我猜这个过程分配了大量内存,正如我之前测量的那样,执行时间比创建事务和插入数据要多得多。

String sql = "INSERT INTO table (col1, col2) VALUES (?, ?)";
db.beginTransaction();

SQLiteStatement stmt = db.compileStatement(sql);
for (int i = 0; i < values.size(); i++) {
    stmt.bindString(1, values.get(i).col1);
    stmt.bindString(2, values.get(i).col2);
    stmt.execute();
    stmt.clearBindings();
}

db.setTransactionSuccessful();
db.endTransaction();

请注意,事务应该在第一次插入之前开始并在最后一次插入之后结束,而不是每个插入的事务。

更多关于 SO 的交易在这里

我知道我的回答可能看起来与问题无关,但我非常肯定这样可以避免错误,并且性能也会得到很大改善。有时最好更改整个逻辑而不是处理错误。

于 2014-12-08T11:24:45.430 回答