2013-05-08 160 views
0

不知道为什么得到错误的参数异常崩溃的android代码。 任何帮助将不胜感激....为什么非法的参数异常?

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    TextView tv=(TextView)findViewById(R.id.test_id); tv.append("\n"); 
    Uri u=Uri.parse("content://sms/inbox"); 
    try{ 
     Toast.makeText(this, getContentResolver().delete(u, "_id like ?", new String[]{"2"})+"", Toast.LENGTH_LONG).show(); 
    }catch(Exception e){ 
     Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); 
    } 
} 
+2

我们可以有堆栈跟踪吗?这将非常有帮助。 – michaelb958 2013-05-08 01:22:09

回答

0

我认为像只能用字符串

Toast.makeText(this, getContentResolver().delete(u, "_id = ?", 
        new String[]{"2"})+"", Toast.LENGTH_LONG).show(); 
+0

感谢您的及时响应。将尽快获得bak给你...... – 2013-05-08 02:01:28

+0

看到我对添加+的评论。这是非常好的.. – 2013-05-08 02:06:58

+0

你是对的,我在阅读时不小心。我以为你添加“”到新的String []。发布您的日志猫 – 2013-05-08 02:23:57

1

的删除URI中使用的 “内容://短信/” + ID;

Cursor c = getApplicationContext().getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null,null); 
try { 
     while (c.moveToNext()) { 
     int id = c.getInt(0); 
     getApplicationContext().getContentResolver().delete(Uri.parse("content://sms/" + id), null, null); 
     } 

    }catch(Exception e){ 
     Log.e(this.toString(),"Error deleting sms",e); 
    }finally { 
     c.close(); 
    } 
+0

+是完全正确的。它不是错误。我只是通过添加空白将返回的结果转换为字符串。 – 2013-05-08 02:06:13

+0

更为标准的方法是调用toString(),它可能更高效,更可读。 – 2013-05-08 02:12:43

+0

另外,buptcoder实际上并不是在抱怨+,他正在回答你的问题......你需要给你的uri添加一个id。 – 2013-05-08 02:13:55