android.content.res.resources notfoundexception$android.content.res.resources notfoundexception$string资源id#0x1
Iam正在使用CustomMultiAutoCompleteTextView选择多个联系人,该代码中引用了选择多个联系人,但我想显示在toast消息中选择的号码。当点击该按钮时,我修改了该代码 在android.content.res.resources notfoundexception$android.content.res.resources notfoundexception$string资源id#0x1,android,Android,Iam正在使用CustomMultiAutoCompleteTextView选择多个联系人,该代码中引用了选择多个联系人,但我想显示在toast消息中选择的号码。当点击该按钮时,我修改了该代码 在main.xml中 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" and
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>
用于在此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
CustomMultiAutoCompleteTextView.java
公共void init(上下文){
....
this.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
...
con.put(contact.num.toString(),contact.contactName.toString());
}
});
}
我修改了
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());
}
}
}
public类MainActivity扩展活动实现OnClickListener{
按钮b1;
私有CustomMultiAutoCompleteTextView phoneNum;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
phoneNum=(CustomMultiAutoCompleteTextView)
findViewById(R.id.editText);
ContactPickerAdapter ContactPickerAdapter=新的ContactPickerAdapter(此,
android.R.layout.simple\u list\u item\u 1,SmsUtil.getContacts(
这个,假),;
设置适配器(contactPickerAdapter);
b1=(按钮)findViewById(R.id.button1);
b1.setOnClickListener((OnClickListener)this);
//addTextChangedListener((TextWatcher));
}
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
CustomMultiAutoCompleteTextView phoneNum=(CustomMultiAutoCompleteTextView)findViewById(R.id.editText);
HashMap map=(HashMap)phoneNum.con;
试一试{
Toast.makeText(this,map.size(),Toast.LENGTH_LONG.show();
}捕获(例外e)
{
Log.e(“eee”,e.toString());
}
}
}
现在,在执行之后,我选择了一个联系人,如果我按下按钮,我将无法获取地图大小()
我正在那里获取android.content.res.resources$notfoundexception字符串资源id#0x1
我能知道为什么会发生这个错误吗。如何在主要活动中获取选定的联系人信息任何机构都可以帮助我解决此问题更改此项:
Toast.makeText(this, map.size(), Toast.LENGTH_LONG).show();
为此:
Toast.makeText(this, String.valueOf(map.size()), Toast.LENGTH_LONG).show();
有两个版本的Toast.makeText
。其中一个参数是字符串,另一个参数是int资源id
您正在向它传递一个intmap.size()
,它认为这是一个无法找到的资源id。因此,您得到的是android.content.res.resources.notfoundexception
您应该包括错误日志。我包括在内。我在访问地图时出错。单击“确定”按钮中的size()它可以工作吗?我可以知道如何在该地图中获取选定的联系人,即姓名和联系人号码吗?当你得到正确答案时,别忘了放弃投票答案]我可以放弃投票,因为我的声誉很低,我只能在15岁以后才可以投票
Toast.makeText(this, String.valueOf(map.size()), Toast.LENGTH_LONG).show();