【问题标题】:android.content.res.resources notfoundexception $android.content.res.resources notfoundexception $ string resource id #0x1android.content.res.resources notfoundexception $android.content.res.resources notfoundexception $ string 资源 ID #0x1
【发布时间】:2013-10-25 05:18:07
【问题描述】:

我在选择多个联系人的代码中使用 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 我能知道为什么会出现这个错误吗?如何在主要活动中获取选定的联系信息任何机构帮助我解决这个问题

【问题讨论】:

  • 你应该包含你的错误日志。
  • 我包括在内。在按钮单击中访问 map.size() 时出现错误

标签: android


【解决方案1】:

改变这个:

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

到这里:

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

Toast.makeText 有 2 个版本。一个,第二个参数是一个字符串,另一个是一个int资源ID。

你传递给它一个 int map.size() 并且它认为它是一个资源 id,它找不到。因此你得到android.content.res.resources.notfoundexception

【讨论】:

  • 好的,它正在工作,我可以知道如何获取选定的联系人,即该地图中的姓名和联系电话
  • 当你得到正确答案时,别忘了给答案投票]
  • 我可以放弃投票,因为我的声誉很低,我只能在 15 岁之后投票
猜你喜欢
  • 2018-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多