簡體   English   中英

android.content.res.resources notfoundexception $ android.content.res.resources notfoundexception $字符串資源ID#0x1

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

蔭選擇使用CustomMultiAutoCompleteTextView wtih參考多個聯系人this在代碼中選擇多個聯系人,但我想顯示什么是烤面包的消息被選中的號碼。 當點擊那個按鈕時,我修改了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我可以知道為什么會出現此錯誤。 如何在主要活動中獲取選定的聯系信息任何機構都可以幫助我解決此問題

更改此:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM