Android中的NoAutoCompleteTextView中的NoSuchMethod异常

时间:2015-12-01 05:40:14

标签: android android-logcat multiautocompletetextview

我通过以下功能获取所有联系人。

public ArrayList<PhoneContactInfo> getAllPhoneContacts() {

        Log.d("START","Getting all Contacts");
        ArrayList<PhoneContactInfo> arrContacts = new ArrayList<PhoneContactInfo>();
        PhoneContactInfo phoneContactInfo=null;     
        Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
        Cursor cursor =  getContentResolver().query(uri, new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone._ID}, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
        cursor.moveToFirst();
        while (cursor.isAfterLast() == false)
        {
            String contactNumber= cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));  
            String contactName =  cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            int phoneContactID = cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID));

            phoneContactInfo = new PhoneContactInfo();
            phoneContactInfo.setPhoneContactID(phoneContactID);             
            phoneContactInfo.setContactName(contactName);                   
            phoneContactInfo.setContactNumber(contactNumber); 
            if (phoneContactInfo != null)
            {
                arrContacts.add(phoneContactInfo);
            }
            phoneContactInfo = null; 
            cursor.moveToNext();
        }       
        cursor.close();
        cursor = null;
        Log.d("END","Got all Contacts");
        return arrContacts;
    }

我已经通过以下代码将适配器设置为MultiAutoCompleteTextView:

phoneContactInfo = getAllPhoneContacts();



    adapter = new AutoCompleteAdapter(this,
                    R.layout.list_item_for_new_message,R.id.contactName ,phoneContactInfo);

            autoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.searchAutoComplete);
            autoCompleteTextView.setAdapter(adapter);

            autoCompleteTextView.setOnItemClickListener(this);

但是我得到以下例外:

12-01 11:34:21.204: E/DeviceUtil(5993): java.lang.NoSuchMethodException: <init> [class android.content.Context, class android.webkit.WebView]
12-01 11:34:21.204: E/DeviceUtil(5993):     at java.lang.Class.getConstructorOrMethod(Class.java:472)
12-01 11:34:21.204: E/DeviceUtil(5993):     at java.lang.Class.getDeclaredConstructor(Class.java:562)
12-01 11:34:21.204: E/DeviceUtil(5993):     at com.mobvista.sdk.m.a.f.b.o(ProGuard:338)
12-01 11:34:21.204: E/DeviceUtil(5993):     at com.mobvista.sdk.m.core.MobvistaAd.init(ProGuard:43)
12-01 11:34:21.204: E/DeviceUtil(5993):     at com.pinguo.camera360.PgCameraApplication.onCreateByMainProcess(PgCameraApplication.java:329)
12-01 11:34:21.204: E/DeviceUtil(5993):     at com.pinguo.camera360.PgCameraApplication.onCreate(PgCameraApplication.java:227)
12-01 11:34:21.204: E/DeviceUtil(5993):     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
12-01 11:34:21.204: E/DeviceUtil(5993):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4579)
12-01 11:34:21.204: E/DeviceUtil(5993):     at android.app.ActivityThread.access$1500(ActivityThread.java:151)
12-01 11:34:21.204: E/DeviceUtil(5993):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1402)
12-01 11:34:21.204: E/DeviceUtil(5993):     at android.os.Handler.dispatchMessage(Handler.java:110)
12-01 11:34:21.204: E/DeviceUtil(5993):     at android.os.Looper.loop(Looper.java:193)
12-01 11:34:21.204: E/DeviceUtil(5993):     at android.app.ActivityThread.main(ActivityThread.java:5330)
12-01 11:34:21.204: E/DeviceUtil(5993):     at java.lang.reflect.Method.invokeNative(Native Method)
12-01 11:34:21.204: E/DeviceUtil(5993):     at java.lang.reflect.Method.invoke(Method.java:515)
12-01 11:34:21.204: E/DeviceUtil(5993):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
12-01 11:34:21.204: E/DeviceUtil(5993):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
12-01 11:34:21.204: E/DeviceUtil(5993):     at dalvik.system.NativeStart.main(Native Method)

为什么我收到此错误?我怎么解决这个问题?

12-01 11:50:54.451: E/ActivityThread(9137): RuntimeExceptionjava.lang.RuntimeException: Unable to start activity ComponentInfo{com.commlink.messaging/com.commlink.messaging.New_Message}: android.view.InflateException: Binary XML file line #13: Error inflating class MultipleAutoCompleteTextView

我的xml布局如下

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >



    <MultipleAutoCompleteTextView
        android:id="@+id/searchAutoComplete"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:hint="To (Search by number or name)"
        android:layout_alignParentTop="true"
        android:inputType="textAutoComplete|textAutoCorrect" />

        <View
             android:layout_width="fill_parent"
             android:layout_height="2dp"
        android:layout_alignParentBottom="true"
        android:layout_above="@+id/linear"
             android:background="#c0c0c0"/>

    <LinearLayout
        android:id="@+id/linear"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_alignParentBottom="true" >

        <EditText
            android:id="@+id/editText2"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:hint="Type message"
            android:ems="10" >

            <requestFocus />
        </EditText>

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:src="@drawable/send_message" />

    </LinearLayout>

</RelativeLayout>

1 个答案:

答案 0 :(得分:4)

仔细检查您是否为MultiAutoCompleteTextView创建了对象。

autoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.searchAutoComplete);

并在您的xml中将其写为MultipleAutoCompleteTextView

<MultipleAutoCompleteTextView
    android:id="@+id/searchAutoComplete"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:hint="To (Search by number or name)"
    android:layout_alignParentTop="true"
    android:inputType="textAutoComplete|textAutoCorrect" />

这将如何运作? Android中没有一个名为MultipleAutoCompleteTextView的班级将其更改为MultiAutoCompleteTextView