2014-06-27 40 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

相關問題