android.content.res.resources notfoundexception $ android.content.res.resources notfoundexception $ string resource id#0x1

时间:2013-10-25 05:18:07

标签: android

我使用CustomMultiAutoCompleteTextView选择多个联系人,并在该代码中引用this选择多个联系人,但我想显示在toast消息中选择的号码是什么。单击按钮时,我修改了该代码 在main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.krishna.widget.CustomMultiAutoCompleteTextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/editText" 
        android:textColor="@android:color/black"/>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         android:text="Button" />

</LinearLayout>

我在CustomMultiAutoCompleteTextView.java

中添加了此字段
public HashMap<String, String> con=new HashMap<String, String>();

用于保存此Hashmap

中的联系号码

我修改了

CustomMultiAutoCompleteTextView.java


public void init(Context context){


....

this.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {

...
con.put(contact.num.toString(), contact.contactName.toString());
}
});

    }
and i modified 
MainActivity.java
像这样

public class MainActivity extends Activity implements OnClickListener{
    Button b1;
    private CustomMultiAutoCompleteTextView phoneNum;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        phoneNum = (CustomMultiAutoCompleteTextView)
                findViewById(R.id.editText);
        ContactPickerAdapter contactPickerAdapter = new ContactPickerAdapter(this,
                android.R.layout.simple_list_item_1, SmsUtil.getContacts(
                    this, false));
        phoneNum.setAdapter(contactPickerAdapter);
        b1=(Button)findViewById(R.id.button1);
        b1.setOnClickListener((OnClickListener) this);
        //phoneNum.addTextChangedListener((TextWatcher));
        }
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        CustomMultiAutoCompleteTextView phoneNum=(CustomMultiAutoCompleteTextView)findViewById(R.id.editText);
        HashMap<String, String> map=(HashMap<String, String>)phoneNum.con;

        try{



            Toast.makeText(this, map.size(), Toast.LENGTH_LONG).show();
        }catch(Exception e)
        {
            Log.e("eee",e.toString());
        }

    }




    }

现在是艺术家执行我选择了一个联系人,如果我按下按钮我unable to get map size() 我得到android.content.res.resources$notfoundexception string resource id #0x1 我能知道为什么会出现这个错误。如何在主要活动中获取选定的联系信息任何正文帮助我解决这个问题

1 个答案:

答案 0 :(得分:2)

改变这个:

Toast.makeText(this, map.size(), Toast.LENGTH_LONG).show();

对此:

Toast.makeText(this, String.valueOf(map.size()), Toast.LENGTH_LONG).show();

Toast.makeText有2个版本。在一个中,第二个参数是String,另一个是int资源id。

你传递的是一个int map.size(),它认为它是一个无法找到的资源ID。因此,您将获得android.content.res.resources.notfoundexception

相关问题