日期:2014-05-20  浏览次数:20807 次

id cannot be resolved or is not a field怎么解决?
程序里总是会报这个错,google了一下,有人说是import R,但是仔细查也没有这行代码,不知道是什么问题

求助
Java code

package test.contentpickertester;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class ContentPickerTester extends Activity {
    /** Called when the activity is first created. */
    
    public static final int PICK_CONTACT = 1;
    
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.contentpickertester);
        
        Button button = (Button)findViewById(R.id.pick_contact_button);
        button.setOnClickListener(new OnClickListener(){
            public void onClick(View _view){
                Intent intent = new Intent(Intent.ACTION_PICK,
                        Uri.parse("content://contacts/"));
                startActivityForResult(intent,PICK_CONTACT);
            }
        });
    }
    @Override
    public void onActivityResult(int reqCode,int resCode,Intent data){
        super.onActivityResult(resCode,resCode,data);
        
        switch (reqCode){
        case(PICK_CONTACT):{
            if(resCode == Activity.RESULT_OK){
                Uri contactData = data.getData();
                Cursor c = managedQuery(contactData,null,null,null,null);
                c.moveToFirst();
                String name;
                name = c.getString(c.getColumnIndexOrThrow(People.NAME));
                TextView tv;
                tv = (TextView)findViewById(R.id.selected.contact.textview);
                tv.setText(name);
            }
            break;
        }
        }
        }
}



------解决方案--------------------
哪一行报错?这个 Activity 的布局 XML 是怎么写的?
------解决方案--------------------
你这个是 Android 的问题,建议移至 Android 版块吧,否则这个帖子在这里会感到孤单的。

移帖方法:点击标题上方的“管理菜单”,选择“移动”,大版块选“移动平台”,小版块选“Android”,点“确定”就可以了。