2014-06-27 41 views
-1

我的Android应用程序出现问题。我想用InputMethodManager类运行项目,但Eclipse向我显示错误应用程序意外停止为什么eclipse显示错误应用程序意外停止。请在类InputMethodManager中再次尝试?

我不使用任何方法,只创建InputMethodManager的实例。我不知道什么是错的。

我的代码:

private static InputMethodManager inputMethodManager; 

private static EditText editText; 

private static String stringInstance; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_input_method_manager); 

    if (savedInstanceState == null) { 
     getSupportFragmentManager().beginTransaction() 
       .add(R.id.container, new PlaceholderFragment()).commit(); 
    } 

    inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 

} 

我的错误日志:

06-27 16:03:11.631: E/PhonePolicy(32): Could not preload class for phone policy: com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback 
06-27 16:03:26.411: E/BatteryService(80): usbOnlinePath not found 
06-27 16:03:26.411: E/BatteryService(80): batteryVoltagePath not found 
06-27 16:03:26.411: E/BatteryService(80): batteryTemperaturePath not found 
06-27 16:03:30.851: E/EventHub(80): could not get driver version for /dev/input/mouse0, Not a typewriter 
06-27 16:03:30.851: E/EventHub(80): could not get driver version for /dev/input/mice, Not a typewriter 
06-27 16:03:31.082: E/WifiService(80): Invoking mWifiStateMachine.setWifiEnabled 
06-27 16:03:32.541: E/ThrottleService(80): Could not open GPS configuration file /etc/gps.conf 
06-27 16:03:32.551: E/NetworkTimeUpdateService(80): Could not open GPS configuration file /etc/gps.conf 
06-27 16:03:32.551: E/NetworkTimeUpdateService(80): NTP server address not found, not syncing to NTP time 
06-27 16:03:33.342: E/logwrapper(161): executing /system/bin/tc failed: No such file or directory 
06-27 16:03:33.421: E/logwrapper(162): executing /system/bin/tc failed: No such file or directory 
06-27 16:03:33.451: E/logwrapper(163): executing /system/bin/tc failed: No such file or directory 
06-27 16:03:43.192: E/SoundPool(80): error loading /system/media/audio/ui/Effect_Tick.ogg 
06-27 16:03:43.192: E/SoundPool(80): error loading /system/media/audio/ui/Effect_Tick.ogg 
06-27 16:03:43.202: E/SoundPool(80): error loading /system/media/audio/ui/Effect_Tick.ogg 
06-27 16:03:43.202: E/SoundPool(80): error loading /system/media/audio/ui/Effect_Tick.ogg 
06-27 16:03:43.212: E/SoundPool(80): error loading /system/media/audio/ui/Effect_Tick.ogg 
06-27 16:03:43.262: E/SoundPool(80): error loading /system/media/audio/ui/KeypressStandard.ogg 
06-27 16:03:43.272: E/SoundPool(80): error loading /system/media/audio/ui/KeypressSpacebar.ogg 
06-27 16:03:43.322: E/SoundPool(80): error loading /system/media/audio/ui/KeypressDelete.ogg 
06-27 16:03:43.332: E/SoundPool(80): error loading /system/media/audio/ui/KeypressReturn.ogg 
06-27 16:03:43.542: E/TelephonyManager(80): Hidden constructor called more than once per process! 
06-27 16:03:43.542: E/TelephonyManager(80): Original: android, new: android 
06-27 16:03:59.692: E/AndroidRuntime(378): FATAL EXCEPTION: main 
06-27 16:03:59.692: E/AndroidRuntime(378): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.imm/com.example.imm.InputMethodManager}: java.lang.ClassCastException: android.view.inputmethod.InputMethodManager cannot be cast to com.example.imm.InputMethodManager 
06-27 16:03:59.692: E/AndroidRuntime(378): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1748) 
06-27 16:03:59.692: E/AndroidRuntime(378): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764) 
06-27 16:03:59.692: E/AndroidRuntime(378): at android.app.ActivityThread.access$1500(ActivityThread.java:122) 
06-27 16:03:59.692: E/AndroidRuntime(378): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002) 
06-27 16:03:59.692: E/AndroidRuntime(378): at android.os.Handler.dispatchMessage(Handler.java:99) 
06-27 16:03:59.692: E/AndroidRuntime(378): at android.os.Looper.loop(Looper.java:132) 
06-27 16:03:59.692: E/AndroidRuntime(378): at android.app.ActivityThread.main(ActivityThread.java:4025) 
06-27 16:03:59.692: E/AndroidRuntime(378): at java.lang.reflect.Method.invokeNative(Native Method) 
06-27 16:03:59.692: E/AndroidRuntime(378): at java.lang.reflect.Method.invoke(Method.java:491) 
06-27 16:03:59.692: E/AndroidRuntime(378): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 
06-27 16:03:59.692: E/AndroidRuntime(378): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 
06-27 16:03:59.692: E/AndroidRuntime(378): at dalvik.system.NativeStart.main(Native Method) 
06-27 16:03:59.692: E/AndroidRuntime(378): Caused by: java.lang.ClassCastException: android.view.inputmethod.InputMethodManager cannot be cast to com.example.imm.InputMethodManager 
06-27 16:03:59.692: E/AndroidRuntime(378): at com.example.imm.InputMethodManager.onCreate(InputMethodManager.java:35) 
06-27 16:03:59.692: E/AndroidRuntime(378): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048) 
06-27 16:03:59.692: E/AndroidRuntime(378): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712) 
06-27 16:03:59.692: E/AndroidRuntime(378): ... 11 more 
: E/(): Device disconnected 

回答

0

您输入了错误的InputMethodManager类,看看你的例外:

Unable to start activity ComponentInfo{com.example.imm/com.example.imm.InputMethodManager}: java.lang.ClassCastException: android.view.inputmethod.InputMethodManager cannot be cast to com.example.imm.InputMethodManager

只要改变import com.example.imm.InputMethodManager;import android.view.inputmethod.InputMethodManager; i你的Java文件的顶部。

+0

如果我导入android.view.inputmethod.InputMethodManager Eclipse视图2选项旁边的导入:删除未使用的导入和组织导入。 – user3770088

+0

我解决了这个问题。感谢帮助。 – user3770088

相关问题