方法返回java.lang.IllegalArgumentException?
我正在尝试插入联系人及其内容 uri Contacts.CONTENT_URI
我只是声明以下代码来插入值: -
public void runContact()
{
Uri u = Contacts.CONTENT_URI;
ContentValues initialValues = new ContentValues();
initialValues.put("data1", "1234567890");
initialValues.put("data2", "Emergency");
initialValues.put("data3", "Number");
cr.query(u, null, null, null, null);
Cursor cursor1 = getContentResolver().query(u, null, null, null, null);
if (cursor1.moveToFirst())
{
do {
if((cursor1.getString(cursor1.getColumnIndex("address"))).equalsIgnoreCase("9953834074111"))
{
String data1 = cursor1.getString(cursor1.getColumnIndex("data1"));
String data2 = cursor1.getString(cursor1.getColumnIndex("data2"));
String data3 = cursor1.getString(cursor.getColumnIndex("data3"));
Log.v("data1",data1);
Log.v("data2",data2);
Log.v("data3", data3);
}
} while (cursor1.moveToNext());
}
}
每当我调用此方法时,它都会返回这样的异常 -
java.lang.IllegalArgumentException: URI: content://contacts, 调用 user: com.android.data, 调用 package:com.android.data
为什么会发生这种情况?我在该代码中做错了什么?有人指导我吗?
I'm trying to insert the contacts with their content uri Contacts.CONTENT_URI
I just declaring the following code for inserting the valuse : -
public void runContact()
{
Uri u = Contacts.CONTENT_URI;
ContentValues initialValues = new ContentValues();
initialValues.put("data1", "1234567890");
initialValues.put("data2", "Emergency");
initialValues.put("data3", "Number");
cr.query(u, null, null, null, null);
Cursor cursor1 = getContentResolver().query(u, null, null, null, null);
if (cursor1.moveToFirst())
{
do {
if((cursor1.getString(cursor1.getColumnIndex("address"))).equalsIgnoreCase("9953834074111"))
{
String data1 = cursor1.getString(cursor1.getColumnIndex("data1"));
String data2 = cursor1.getString(cursor1.getColumnIndex("data2"));
String data3 = cursor1.getString(cursor.getColumnIndex("data3"));
Log.v("data1",data1);
Log.v("data2",data2);
Log.v("data3", data3);
}
} while (cursor1.moveToNext());
}
}
Whenever i called this method, it returns an exception like this -
java.lang.IllegalArgumentException: URI: content://contacts, calling user: com.android.data, calling package:com.android.data
Why this happened? What i'm doing wrong in that code? Anyone guide me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试像下面的代码:
Try like below code: