0

我正在尝试将此插件合并到我的一个片段中。我喜欢我的 gradle 文件中的依赖关系:

compile "com.splitwise:tokenautocomplete:1.3.1@aar"

我的片段 onCreateView 看起来像:

View view = inflater.inflate(R.layout.fragment_tutor_setup, container, false);

    String[] strings = new String[]{"photoshop",""};

    adapter = new ArrayAdapter<String>(getActivity(), R.layout.fragment_tutor_setup, strings);

    completionView = (ContactsCompletionView)view.findViewById(R.id.searchView);
    completionView.setAdapter(adapter);

    if (savedInstanceState == null) {
        completionView.setPrefix("Skills: ");
    }
    return view;

然后我像这样扩展一个 ContactsCompletionView:

public class ContactsCompletionView extends TokenCompleteTextView {

    public ContactsCompletionView(Context context) {
        super(context);
    }
    public ContactsCompletionView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public ContactsCompletionView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    @Override
    protected View getViewForObject(Object object) {
        String s = (String)object;

        LayoutInflater l = (LayoutInflater)getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        LinearLayout view = (LinearLayout)l.inflate(R.layout.contact_token, (ViewGroup)ContactsCompletionView.this.getParent(), false);
        ((TextView)view.findViewById(R.id.name)).setText(s);

        return view;
    }
    @Override
    protected Object defaultObject(String completionText) {
        return completionText;
    }

}

最后在我的 fragment_tutor_setup.xml 中:

<com.tokenautocomplete.ContactsCompletionView
    android:id="@+id/searchView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

**编辑堆栈**

02-23 11:20:43.041  29587-29587/login.shogun.comet.samplelogin E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: login.shogun.comet.samplelogin, PID: 29587
android.view.InflateException: Binary XML file line #34: Error inflating class login.shogun.comet.halp.ContactsCompletionView
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
        at login.shogun.comet.halp.TutorSetupFragment.onCreateView(TutorSetupFragment.java:76)
        at android.app.Fragment.performCreateView(Fragment.java:2053)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
        at android.app.BackStackRecord.run(BackStackRecord.java:833)
        at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
        at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "login.shogun.comet.halp.ContactsCompletionView" on path: DexPathList[[zip file "/data/app/login.shogun.comet.samplelogin-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
        at android.view.LayoutInflater.createView(LayoutInflater.java:571)
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

我知道我之前遇到过这个问题,所以首先重建我的项目并使缓存无效。如果您希望我发布更多代码,我也会非常高兴。

4

1 回答 1

5

在您的布局 xml 中,它应该是:

<login.shogun.comet.halp.ContactsCompletionView
    android:id="@+id/searchView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

或您的班级的完全限定名称是什么。

于 2015-06-04T18:48:06.563 回答