运行Android的TouchPaint示例程序时出错

发布于 2024-12-27 08:45:52 字数 4029 浏览 0 评论 0原文

我只是尝试 Google Android 示例提供的“TouchPaint”示例:

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

创建了我自己的AndroidManifest.xml,在我成功编译并创建apk之前,我发现“GraphicsActivity.java”和“PictureLayout.java”是另外两个java文件。

当我加载到我的 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

我很困惑崩溃的可能原因是什么?

I am just trying out the "TouchPaint" sample provided by Google Android examples at:

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

Created my own AndroidManifest.xml, and I figured that "GraphicsActivity.java" and "PictureLayout.java" are two other java files before I could compiled and create the apk successfully.

After I load into my Android phone, it displayed a blank screen. At this point nothing happened yet, but once I touch the screen, the apps died, and generated the following trace in logcat output:

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

I am puzzled over what is the possible cause of crashing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

网白 2025-01-03 08:45:52

此方法仅从 API Level 14 开始可用,在 Manifest 中将 minSdkVersion 设置为 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.

This method is only available since API Level 14, set minSdkVersion to 14 in the Manifest

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.
浅紫色的梦幻 2025-01-03 08:45:52

我找到了答案:

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,在 AndroidManifest.xml 文件中将 minSDK 版本更改为 10:

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

一切正常!也感谢 Rajdeep Dua!!!

I found the answer:

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

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

From the web page's table, since I know my phone is using Android 2.3.4, so that max target API for SDK should be 10. So instead of using the TouchPaint.java sample from android-14, I copied the TouchPaint.java from android-10,change the minSDK version to 10 inside my AndroidManifest.xml file:

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

Everything works!! Thanks to Rajdeep Dua too!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文