2012-01-18 55 views
0

我只是想通過走出谷歌Android的例子,在提供的「TouchPaint」樣本:錯誤在運行Android的TouchPaint示例程序

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchPaint.html

創建了自己的AndroidManifest.xml中,我計算過,「GraphicsActivity。 java「和」PictureLayout.java「是兩個其他的Java文件,然後才能編譯併成功創建apk。

當我加載到我的Android手機後,它顯示一個空白屏幕。在這一點上沒有發生過,但一旦我觸摸屏幕時,應用程序死亡,生成的logcat輸出以下跟蹤:

D/dalvikvm(4939): GC_CONCURRENT freed 44K, 49% free 2779K/5379K, external 3286K/4104K, paused 4ms+2ms 
D/dalvikvm( 365): GC_CONCURRENT freed 1102K, 54% free 3271K/7047K, external 2612K/3262K, paused 4ms+4ms 
I/ActivityManager( 266): Displayed com.example.android.apis.graphics/.TouchPaint: +382ms 
D/AndroidRuntime(4939): Shutting down VM 
W/dalvikvm(4939): threadid=1: thread exiting with uncaught exception (group=0x2aac8578) 
E/AndroidRuntime(4939): FATAL EXCEPTION: main 
E/AndroidRuntime(4939): java.lang.NoSuchMethodError: android.view.MotionEvent.getButtonState 
E/AndroidRuntime(4939): at com.example.android.apis.graphics.TouchPaint$PaintView.onTouchOrHoverEvent(TouchPaint.java:346) 
E/AndroidRuntime(4939): at com.example.android.apis.graphics.TouchPaint$PaintView.onTouchEvent(TouchPaint.java:337) 
E/AndroidRuntime(4939): at android.view.View.dispatchTouchEvent(View.java:3952) 
E/AndroidRuntime(4939): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:961) 
E/AndroidRuntime(4939): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:961) 
E/AndroidRuntime(4939): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1711) 
E/AndroidRuntime(4939): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1145) 
E/AndroidRuntime(4939): at android.app.Activity.dispatchTouchEvent(Activity.java:2096) 
E/AndroidRuntime(4939): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1695) 
E/AndroidRuntime(4939): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2217) 
E/AndroidRuntime(4939): at android.view.ViewRoot.handleMessage(ViewRoot.java:1901) 
E/AndroidRuntime(4939): at android.os.Handler.dispatchMessage(Handler.java:99) 
E/AndroidRuntime(4939): at android.os.Looper.loop(Looper.java:130) 
E/AndroidRuntime(4939): at android.app.ActivityThread.main(ActivityThread.java:3701) 
E/AndroidRuntime(4939): at java.lang.reflect.Method.invokeNative(Native Method) 
E/AndroidRuntime(4939): at java.lang.reflect.Method.invoke(Method.java:507) 
E/AndroidRuntime(4939): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
E/AndroidRuntime(4939): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624) 
E/AndroidRuntime(4939): at dalvik.system.NativeStart.main(Native Method) 
W/ActivityManager( 266): Force finishing activity com.example.android.apis.graphics/.TouchPaint 
W/ActivityManager( 266): Activity pause timeout for HistoryRecord{2afed900 com.example.android.apis.graphics/.TouchPaint} 
I/InputDispatcher( 266): Application is not responding: Window{2b3f4d00 com.example.android.apis.graphics/com.example.android.apis.graphics.TouchPaint paused=false}. 5002.0ms since event, 5001.8ms since wait started 
I/InputDispatcher( 266): Dropping event because the pointer is not down. 
I/WindowManager( 266): Input event dispatching timed out sending to com.example.android.apis.graphics/com.example.android.apis.graphics.TouchPaint 
W/ActivityManager( 266): Activity destroy timeout for HistoryRecord{2afed900 com.example.android.apis.graphics/.TouchPaint} 
D/lights ( 266): set_light_backlight: brightness=20 
I/ActivityManager( 266): No longer want com.facebook.katana (pid 4319): hidden #16 
W/ActivityManager( 266): Scheduling restart of crashed service com.facebook.katana/.service.UploadManager in 5000ms 

我對什麼是崩潰的可能原因疑惑?

回答

1

這種方法只因爲API等級14可在清單

public final int getButtonState() 

Since: API Level 14 
Gets the state of all buttons that are pressed such as a mouse or stylus button. 
Returns 

The button state. 
+0

感謝您的信息,之後,我在安裝過程中出現錯誤: 失敗[INSTALL_FAILED_OLDER_SDK],但我的SDK已經在1.6,並且樣本從android-14目錄本身複製? – 2012-01-18 09:24:55

+0

你需要確保在屬性中選擇了正確的android版本。 – 2012-01-18 09:26:41

0

設置的minSdkVersion 14我找到了答案:

http://developer.android.com/resources/dashboard/platform-versions.html

http://developer.android.com/guide/appendix/api-levels.html

從網絡因爲我知道我的手機正在使用Android 2.3.4,所以SDK的最大目標API應該是10.因此而不是我們從Android的14荷蘭國際集團的TouchPaint.java樣品,我從Android的10複製TouchPaint.java,改變minSDK版本10我的AndroidManifest.xml文件中:

<uses-sdk android:minSdkVersion="10"/> 

一切正常!感謝Rajdeep Dua!