所以我在下面的switch语句中得到了一个无法访问的语句。我无法弄清楚为什么会这样,任何帮助都会非常感激。
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
SQLiteDatabase db = psHelper.getWritableDatabase();
int delCount = 0;
return 0;
switch (URI_MATCHER.match(uri)) {
case PRODUCT_LIST:
// THE LINE BELOW IS UNREACHABLE
delCount = db.delete(TABLE_NAME_PRODUCTS, selection, selectionArgs);
break;
case PRODUCT_ID:
String idStr = uri.getLastPathSegment();
String where = PSContract.Products.ID_COLUMN + " = " + idStr;
if (!TextUtils.isEmpty(selection)) {
where += " AND " + selection;
}
delCount = db.delete(TABLE_NAME_PRODUCTS, where, selectionArgs);
break;
case SUPPLIER_LIST:
delCount = db.delete(TABLE_NAME_SUPPLIERS, selection, selectionArgs);
break;
case SUPPLIER_ID:
String idStr2 = uri.getLastPathSegment();
String where2 = PSContract.Products.ID_COLUMN + " = " + idStr2;
if (!TextUtils.isEmpty(selection)) {
where2 += " AND " + selection;
}
delCount = db.delete(TABLE_NAME_SUPPLIERS, where2, selectionArgs);
break;
default:
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return delCount;
}
答案 0 :(得分:5)
你在开关前回来0。
,如果从之前的方法返回,则无法访问切换,因此会生成错误。答案 1 :(得分:1)
在int delCount = 0下,您将返回0,这将结束函数调用。因为那个回归所处的地方会在100%的时间内完成任何事情。看起来像是一个错字。