网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
06月28日漏签0天
android开发吧 关注:225,960贴子:949,219
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 1回复贴,共1页
<<返回android开发吧
>0< 加载中...

『求助』高手麻烦看看我的代码有什么错误

  • 只看楼主
  • 收藏

  • 回复
  • 随风走66
  • 学前班
    3
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我的代码是获取联系人的姓名和号码但是总是出错 希望高手帮忙看看
代码
package cn.provider;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;
import android.widget.TextView;
public class provider extends Activity {
/** Called when the activity is first created. */
private TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
String st="";
super.onCreate(savedInstanceState);
tv=(TextView)findViewById(R.id.tv);
setContentView(R.layout.main);
ContentResolver cr=getContentResolver();
Cursor cursor=cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while(cursor.moveToNext())
{
int name=cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String con=cursor.getString(name);
System.out.print(con);
String cont=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
Cursor phone=cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID+"="+cont,null, null);
while(phone.moveToNext())
{
int number=phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String num=phone.getString(number);
st+=con+":"+num+"\n";
}
}
cursor.close();
tv.setText(st);
}
}
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.provider"
android:versionCode="1"
android:versionName="1.0">
<uses-permission
android:name="android.permission.READ_CONTACTS">
</uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".provider"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:text="TextView"
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>


  • 随风走66
  • 学前班
    3
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
这是console显示的信息
[2015-04-19 21:19:33 - Provider] ------------------------------
[2015-04-19 21:19:33 - Provider] Android Launch!
[2015-04-19 21:19:33 - Provider] adb is running normally.
[2015-04-19 21:19:33 - Provider] Performing cn.provider.provider activity launch
[2015-04-19 21:19:33 - Provider] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'avd'
[2015-04-19 21:19:33 - Provider] WARNING: Application does not specify an API level requirement!
[2015-04-19 21:19:33 - Provider] Device API version is 10 (Android 2.3.3)
[2015-04-19 21:19:36 - Provider] Application already deployed. No need to reinstall.
[2015-04-19 21:19:36 - Provider] Starting activity cn.provider.provider on device emulator-5554
[2015-04-19 21:19:38 - Provider] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=cn.provider/.provider }
[2015-04-19 21:19:40 - Provider] Attempting to connect debugger to 'cn.provider' on port 8617


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 1回复贴,共1页
<<返回android开发吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示