Ravi Tewari OS
Ravi Tewari OS

Reputation: 41

Why Illegal Argument Exception?

Dont Know why getting Illgal Argument Exception is crashing the android code. Any help will be appreciated....

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();
    }
}

Upvotes: 0

Views: 126

Answers (2)

Hoan Nguyen
Hoan Nguyen

Reputation: 18151

I think LIKE can only be used with String

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

Upvotes: 0

buptcoder
buptcoder

Reputation: 2702

The delete uri is "content://sms/" + 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();
    }

Upvotes: 1

Related Questions