public Cursor query(Uri paramUri, String[] paramArrayOfString1, String paramString1,String[] paramArrayOfString2, String paramString2)
{
SQLiteQueryBuilder localSQLiteQueryBuilder = new SQLiteQueryBuilder();
if (paramUri.getPathSegments().size() == 1);
for (StringBuilder localStringBuilder = null; ; localStringBuilder = new StringBuilder(100))
switch (sURIMatcher.match(paramUri))
{
case 0:
case 1:
case 2:
case 3:
default:
throw new IllegalArgumentException("Unknown URI " + paramUri);
}
localSQLiteQueryBuilder.setTables("category");//unreachable code
while (true)
{
Cursor localCursor = localSQLiteQueryBuilder.query(mOpenHelper.getReadableDatabase(), paramArrayOfString1, paramString1, paramArrayOfString2, null, null, paramString2);
localCursor.setNotificationUri(contentResolver, paramUri);
return localCursor;
localSQLiteQueryBuilder.setTables("shop,category");
localSQLiteQueryBuilder.appendWhere("shop_category_id=category._id");
continue;
localSQLiteQueryBuilder.setTables("shop,category");
StringBuilder localStringBuilder;
localStringBuilder.append("shop_category_id=category._id");
localStringBuilder.append(" AND ");
localStringBuilder.append("_id");
localStringBuilder.append('=');
localStringBuilder.append((String)paramUri.getPathSegments().get(1));
localSQLiteQueryBuilder.appendWhere(localStringBuilder.toString());
continue;
localSQLiteQueryBuilder.setTables("shop,category");
localSQLiteQueryBuilder.setDistinct(true);
localStringBuilder.append("shop_category_id=category._id");
localStringBuilder.append(" AND ");
localStringBuilder.append("shop_category_id");
localStringBuilder.append('=');
localStringBuilder.append((String)paramUri.getPathSegments().get(1));
localSQLiteQueryBuilder.appendWhere(localStringBuilder.toString());
paramString2 = "shop._id";
}
}
我在switch语句后出现无法访问的代码错误,我无法弄清楚如何解决它。我试图删除该行但如果我这样做,我会收到很多错误。我的代码在上面。任何人都可以帮助我?提前谢谢。
答案 0 :(得分:4)
代码真的无法访问:
所有案例都是落空的(它们没有break
语句,所以匹配后的所有案例都会执行)并以default
案例结束,这会引发Exception
。这意味着抛出Exception
后的代码永远不会被执行。
也许你打算做的事情就是这样:
switch (sURIMatcher.match(paramUri)){
case 0:
// do something
break;
case 1:
// do something
break;
case 2:
// do something
break;
case 3:
// do something
break;
default:
throw new IllegalArgumentException("Unknown URI " + paramUri);
}
答案 1 :(得分:1)
我想这是因为你的开关不好......你必须使用break;
switch (sURIMatcher.match(paramUri))
{
case 0:
//your code
break;
case 1:
//your code
break;
case 2:
//your code
break;
case 3:
//your code
break;
default:
//your code
break;
}