2013-05-08 4 views
0

Dont 왜 Illgal Argument Exception을받는 것이 안드로이드 코드를 크래킹하는지 알 수 있습니다. 어떤 도움을 이해할 수있을 것이다 ....왜 잘못된 인수 예외입니까?

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

답변

0

내가 LIKE는 문자열

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

답장을 보내 주셔서 감사합니다. 첵하고 빨리 박쥐를 얻을 것이다 ... –

+0

+에 대한 덧글을 참조하십시오. 그것은 완벽하게 괜찮습니다. –

+0

당신이 옳습니다, 나는 독서 할 때 조심하지 않습니다. 나는 새로운 String []에 ""을 추가한다고 생각했습니다. 귀하의 로그 고양이 –

1

h 제 URI와 함께 사용할 수 있습니다 생각한다 "는 내용 : // 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(); 
    } 
+0

+를 게시 완벽하게 괜찮습니다. 오류가 아닙니다. 그냥 공백을 추가하여 반환 된 결과를 문자열로 변환하는 중입니다. –

+0

보다 표준적인 방법은 toString()을 호출하는 것입니다.이 방법은 아마 더 효율적이고 명확하게 읽을 수 있습니다. –

+0

또한, buptcoder 실제로 +에 대해 불평하지 않습니다, 그는 귀하의 질문에 대답하고있다 ... 당신은 귀하의 uri에 ID를 추가해야합니다. –