2

这是我的资源文件 res/layout/input.xml。My.application - 我的 android 程序的名称

<my.application.android.inputmethodservice.KeyboardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/keyboard"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

Android软键盘在此创建:

public View onCreateInputView() {
        mInputView = (KeyboardView) getLayoutInflater().inflate(R.layout.input,
                null);
        Keyboard keyboard = new Keyboard(this, R.xml.qwerty);
        mInputView.setKeyboard(keyboard);
        mInputView.setEnabled(true);
        mInputView.setPreviewEnabled(true);
        mInputView.setOnKeyboardActionListener(this);
        return mInputView;
    }

应用程序编译没有错误。当我在任何 android 应用程序中调用我的软键盘时,我得到下一个错误:

12-12 09:07:39.183: E/AndroidRuntime(25341): FATAL EXCEPTION: main
12-12 09:07:39.183: E/AndroidRuntime(25341): android.view.InflateException: Binary XML file line #21: Error inflating class my.application.android.inputmethodservice.KeyboardView
12-12 09:07:39.183: E/AndroidRuntime(25341):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at application.my.Keyb.onCreateInputView(Keyb.java:59)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at android.inputmethodservice.InputMethodService.updateInputViewShown(InputMethodService.java:1073)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at android.inputmethodservice.InputMethodService.showWindowInner(InputMethodService.java:1428)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at android.inputmethodservice.InputMethodService.showWindow(InputMethodService.java:1403)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at android.inputmethodservice.InputMethodService$InputMethodImpl.showSoftInput(InputMethodService.java:424)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java:188)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:40)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at android.os.Looper.loop(Looper.java:137)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at android.app.ActivityThread.main(ActivityThread.java:5039)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at java.lang.reflect.Method.invokeNative(Native Method)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at java.lang.reflect.Method.invoke(Method.java:511)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at dalvik.system.NativeStart.main(Native Method)
12-12 09:07:39.183: E/AndroidRuntime(25341): Caused by: java.lang.ClassNotFoundException: Didn't find class "my.application.android.inputmethodservice.KeyboardView" on path: /data/app/application.my-1.apk
12-12 09:07:39.183: E/AndroidRuntime(25341):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at android.view.LayoutInflater.createView(LayoutInflater.java:552)
12-12 09:07:39.183: E/AndroidRuntime(25341):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
12-12 09:07:39.183: E/AndroidRuntime(25341):    ... 18 more
4

3 回答 3

1

在清单文件中试试这个

<service
            android:name="SoftKeyboard"
            android:permission="android.permission.BIND_INPUT_METHOD" >
            <intent-filter>
                <action android:name="android.view.InputMethod" />
            </intent-filter>
于 2012-12-12T05:39:44.213 回答
1

在清单文件中试试这个

<activity android:label="@string/app_name" android:name="my.application.android.inputmethodservice.KeyboardView">

您不需要完全限定的类名。此外,如果您正在使用 Eclipse 并重命名一个包,请转到 Project -> Clean 并让它清理您的项目,修复引用等,如果有任何问题。

于 2012-12-12T05:25:20.617 回答
1

我认为您没有定义服务和权限,请将其粘贴到您的清单文件中

<service android:name="SoftKeyboard"
                android:permission="android.permission.BIND_INPUT_METHOD">
            <intent-filter>
                <action android:name="android.view.InputMethod" />
            </intent-filter>
            <meta-data android:name="android.view.im" android:resource="@xml/method" />
        </service>
于 2012-12-12T05:49:08.453 回答