Android工作室错误:未报告异常Throwable;必须被抓住或宣布被抛出

时间:2016-01-04 16:37:41

标签: java android

你好,我希望你能帮帮我。

我的项目有5个相同类型的错误。

这些是存在错误的方法:

public fresul BulkImportdbOperatori(SQLiteDatabase db, ArrayList<OperatoriXML> elencoOperatori) {
        fresul Ret = new fresul(0, BuildConfig.FLAVOR);
        Throwable th;
        fresul Ret2 = new fresul(0, BuildConfig.FLAVOR);
        db.beginTransaction();
        try {
            db.execSQL("DELETE FROM operatori");
            SQLiteStatement insert = db.compileStatement("INSERT INTO operatori (codice, alfaoperatore, login, password) VALUES (?, ?, ?, ?)");
            for (int i = 0; i < elencoOperatori.size(); i += VERSIONE_DB) {
                insert.bindString(VERSIONE_DB, ((OperatoriXML) elencoOperatori.get(i)).getCodOp());
                insert.bindString(2, ((OperatoriXML) elencoOperatori.get(i)).getAlfaOp());
                insert.bindString(3, ((OperatoriXML) elencoOperatori.get(i)).getLoginOp());
                insert.bindString(4, ((OperatoriXML) elencoOperatori.get(i)).getPwdOp());
                insert.execute();
                insert.clearBindings();
            }
            db.setTransactionSuccessful();
            db.endTransaction();
            return Ret2;
        } catch (Exception e) {
            String errMsg = e.getMessage() == null ? "bulkInsert failed" : e.getMessage();
            Ret = new fresul(-1, errMsg);
            Log.e("bulkInsert:", errMsg);
            db.endTransaction();
            return Ret;
        } catch (Throwable th2) {
            th = th2;
            Ret2 = Ret;
            db.endTransaction();
            throw th;
        }
    }

这是第二种方法:

public fresul BulkImportdbSale(SQLiteDatabase db, ArrayList<SaleXML> elencosale) {
    fresul Ret = new fresul(0, BuildConfig.FLAVOR);
    Throwable th;
    fresul Ret2 = new fresul(0, BuildConfig.FLAVOR);
    db.beginTransaction();
    try {
        db.execSQL("DELETE FROM sale");
        SQLiteStatement insert = db.compileStatement("INSERT INTO sale (codice, alfasala, numerotavoli, deltatavoli) VALUES (?, ?, ?, ?)");
        for (int i = 0; i < elencosale.size(); i += VERSIONE_DB) {
            insert.bindString(VERSIONE_DB, ((SaleXML) elencosale.get(i)).getCodSala());
            insert.bindString(2, ((SaleXML) elencosale.get(i)).getAlfaSala());
            insert.bindString(3, Integer.toString(((SaleXML) elencosale.get(i)).getNumeroTavoli()));
            insert.bindString(4, Integer.toString(((SaleXML) elencosale.get(i)).getDeltaTavoli()));
            insert.execute();
            insert.clearBindings();
        }
        db.setTransactionSuccessful();
        db.endTransaction();
        return Ret2;
    } catch (Exception e) {
        String errMsg = e.getMessage() == null ? "bulkInsert failed" : e.getMessage();
        Ret = new fresul(-1, errMsg);
        Log.e("bulkInsert:", errMsg);
        db.endTransaction();
        return Ret;
    } catch (Throwable th2) {
        th = th2;
        Ret2 = Ret;
        db.endTransaction();
        throw th;
    }
}

这是第三种方法

public fresul BulkImportdbArticoli(SQLiteDatabase db, ArrayList<RepartiXML> elencorep, ArrayList<VariantiXML> elencovar) {
    fresul Ret = new fresul(0, BuildConfig.FLAVOR);
    Throwable th;
    fresul Ret2 = new fresul(0, BuildConfig.FLAVOR);
    db.beginTransaction();
    try {
        int i;
        String cv;
        db.execSQL("DELETE FROM LinkVariantiArticoli");
        db.execSQL("DELETE FROM variantiarticoli");
        SQLiteStatement insertVariante = db.compileStatement("INSERT INTO variantiarticoli (codice, alfavariante, prezzovariante, variantepertutti) VALUES (?, ?, ?, ?)");
        for (i = 0; i < elencovar.size(); i += VERSIONE_DB) {
            cv = ((VariantiXML) elencovar.get(i)).getCodVariante();
            String av = ((VariantiXML) elencovar.get(i)).getAlfaVariante();
            double pv = ((VariantiXML) elencovar.get(i)).getPrezzoVariante();
            boolean gv = ((VariantiXML) elencovar.get(i)).getVariantePerTutti();
            insertVariante.bindString(VERSIONE_DB, cv);
            insertVariante.bindString(2, av);
            insertVariante.bindDouble(3, pv);
            insertVariante.bindLong(4, (long) boolToInt(gv));
            insertVariante.execute();
            insertVariante.clearBindings();
        }
        db.execSQL("DELETE FROM reparti");
        db.execSQL("DELETE FROM articoli");
        SQLiteStatement insertRep = db.compileStatement("INSERT INTO reparti (codice, descrizione, posizione) VALUES (?, ?, ?)");
        SQLiteStatement insertArt = db.compileStatement("INSERT INTO articoli (codice, descrizione, reparto, prezzo, iva, posizione) VALUES (?, ?, ?, ?, ?, ?)");
        SQLiteStatement insertLinkVarArt = db.compileStatement("INSERT INTO LinkVariantiArticoli (codice_articolo, codice_variante) VALUES (?, ?)");
        for (i = 0; i < elencorep.size(); i += VERSIONE_DB) {
            insertRep.bindString(VERSIONE_DB, ((RepartiXML) elencorep.get(i)).getCodRep());
            insertRep.bindString(2, ((RepartiXML) elencorep.get(i)).getAlfaRep());
            insertRep.bindString(3, Integer.toString(((RepartiXML) elencorep.get(i)).getPosizione()));
            insertRep.execute();
            insertRep.clearBindings();
            for (int y = 0; y < ((RepartiXML) elencorep.get(i)).getElencoArt().size(); y += VERSIONE_DB) {
                ArticoliXML art = (ArticoliXML) ((RepartiXML) elencorep.get(i)).getElencoArt().get(y);
                insertArt.bindString(VERSIONE_DB, art.getCodArt());
                insertArt.bindString(2, art.getAlfaArt());
                insertArt.bindString(3, ((RepartiXML) elencorep.get(i)).getCodRep());
                insertArt.bindDouble(4, art.getPrezzoArt());
                insertArt.bindDouble(5, art.getIvaArt());
                insertArt.bindString(6, Integer.toString(art.getPosizione()));
                insertArt.execute();
                insertArt.clearBindings();
                for (int K = 0; K < art.getElencoVarianti().size(); K += VERSIONE_DB) {
                    cv = (String) art.getElencoVarianti().get(K);
                    insertLinkVarArt.bindString(VERSIONE_DB, art.getCodArt());
                    insertLinkVarArt.bindString(2, cv);
                    insertLinkVarArt.execute();
                    insertLinkVarArt.clearBindings();
                }
            }
        }
        db.setTransactionSuccessful();
        db.endTransaction();
        return Ret2;
    } catch (Exception e) {
        String errMsg = e.getMessage() == null ? "bulkInsert failed" : e.getMessage();
        Ret = new fresul(-1, errMsg);
        Log.e("bulkInsert:", errMsg);
        db.endTransaction();
        return Ret;
    } catch (Throwable th2) {
        th = th2;
        Ret2 = Ret;
        db.endTransaction();
        throw th;
    }
}

这是第四种方法

public fresul BulkImportdbCDP(SQLiteDatabase db, ArrayList<InfoCdpXML> elencoCDP) {
        fresul Ret = new fresul(0, BuildConfig.FLAVOR);
        Throwable th;
        fresul Ret2 = new fresul(0, BuildConfig.FLAVOR);
        db.beginTransaction();
        try {
            db.execSQL("DELETE FROM CentriDiProduzione");
            SQLiteStatement insert = db.compileStatement("INSERT INTO CentriDiProduzione (codice, alfacdp) VALUES (?, ?)");
            for (int i = 0; i < elencoCDP.size(); i += VERSIONE_DB) {
                insert.bindString(VERSIONE_DB, ((InfoCdpXML) elencoCDP.get(i)).getCodCDP());
                insert.bindString(2, ((InfoCdpXML) elencoCDP.get(i)).getAlfaCDP());
                insert.execute();
                insert.clearBindings();
            }
            db.setTransactionSuccessful();
            db.endTransaction();
            return Ret2;
        } catch (Exception e) {
            String errMsg = e.getMessage() == null ? "bulkInsert failed" : e.getMessage();
            Ret = new fresul(-1, errMsg);
            Log.e("bulkInsert:", errMsg);
            db.endTransaction();
            return Ret;
        } catch (Throwable th2) {
            th = th2;
            Ret2 = Ret;
            db.endTransaction();
            throw th;
        }
    }

这是最后一次

public fresul BulkImportdbMsgForCDP(SQLiteDatabase db, ArrayList<MsgForCdpXML> elencoMSG) {
    fresul Ret  = new fresul(0, BuildConfig.FLAVOR);
    Throwable th;
    fresul Ret2 = new fresul(0, BuildConfig.FLAVOR);
    db.beginTransaction();
    try {
        db.execSQL("DELETE FROM MsgForCDP");
        SQLiteStatement insert = db.compileStatement("INSERT INTO MsgForCDP (codice, testo, cdp) VALUES (?, ?, ?)");
        for (int i = 0; i < elencoMSG.size(); i += VERSIONE_DB) {
            insert.bindString(VERSIONE_DB, ((MsgForCdpXML) elencoMSG.get(i)).getCodMSG());
            insert.bindString(2, ((MsgForCdpXML) elencoMSG.get(i)).getTestoMSG());
            insert.bindString(3, ((MsgForCdpXML) elencoMSG.get(i)).getCodCDP());
            insert.execute();
            insert.clearBindings();
        }
        db.setTransactionSuccessful();
        db.endTransaction();
        return Ret2;
    } catch (Exception e) {
        String errMsg = e.getMessage() == null ? "bulkInsert failed" : e.getMessage();
        Ret = new fresul(-1, errMsg);
        Log.e("bulkInsert:", errMsg);
        db.endTransaction();
        return Ret;
    } catch (Throwable th2) {
        th = th2;
        Ret2 = Ret;
        db.endTransaction();
        throw th;
    }
}

你能帮我理解发生了什么吗?

1 个答案:

答案 0 :(得分:1)

在你的第二个catch语句中,你再次抛出runnable:

catch (Throwable th2) {
    th = th2;
    Ret2 = Ret;
    db.endTransaction();
    throw th;
}

这就是为什么存在这样的错误,如果你想重新抛出这个异常,你应该像这样声明你的方法:

public fresul BulkImportdbOperatori(SQLiteDatabase db, ArrayList<OperatoriXML> elencoOperatori) throws Throwable