3
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 语句后出现无法访问的代码错误,我无法弄清楚如何解决它。我试图删除该行,但如果我这样做了,我会收到很多错误。我的代码在上面。有人可以帮助我吗?谢谢进步。

4

2 回答 2

5

代码真的无法访问:

所有案例都是失败的(它们没有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); 
  }
于 2013-04-13T19:00:42.777 回答
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;      
 }
于 2013-04-13T19:03:28.980 回答