简体   繁体   English

无法运行android示例代码'bitmapfun'

[英]Unable to run the android sample code 'bitmapfun'

I am trying to run the sample code downloaded from http://developer.android.com/training/displaying-bitmaps/index.html . 我正在尝试运行从http://developer.android.com/training/displaying-bitmaps/index.html下载的示例代码。 All I did was download the code and import it like any other sample codes I tried. 我所做的就是下载代码并将其导入,就像我尝试过的其他任何示例代码一样。 But when I run, 'Unfortunately, BitmapFun has stopped' shows and application exits. 但是当我运行时,“不幸的是,BitmapFun已停止”显示,并且应用程序退出。

My logcat shows : 我的日志显示:

02-07 13:11:55.647: D/AndroidRuntime(5554): Shutting down VM
02-07 13:11:55.647: W/dalvikvm(5554): threadid=1: thread exiting with uncaught exception (group=0x41550ba8)
02-07 13:11:55.647: E/AndroidRuntime(5554): FATAL EXCEPTION: main
02-07 13:11:55.647: E/AndroidRuntime(5554): Process: com.example.android.bitmapfun, PID: 5554
02-07 13:11:55.647: E/AndroidRuntime(5554): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.bitmapfun/com.example.android.bitmapfun.ui.ImageGridActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.android.bitmapfun.ui.ImageGridActivity" on path: DexPathList[[zip file "/data/app/com.example.android.bitmapfun-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.android.bitmapfun-2, /vendor/lib, /system/lib]]
02-07 13:11:55.647: E/AndroidRuntime(5554):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at android.os.Looper.loop(Looper.java:136)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at android.app.ActivityThread.main(ActivityThread.java:5017)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at java.lang.reflect.Method.invokeNative(Native Method)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at java.lang.reflect.Method.invoke(Method.java:515)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at dalvik.system.NativeStart.main(Native Method)
02-07 13:11:55.647: E/AndroidRuntime(5554): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.android.bitmapfun.ui.ImageGridActivity" on path: DexPathList[[zip file "/data/app/com.example.android.bitmapfun-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.android.bitmapfun-2, /vendor/lib, /system/lib]]
02-07 13:11:55.647: E/AndroidRuntime(5554):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
02-07 13:11:55.647: E/AndroidRuntime(5554):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
02-07 13:11:55.647: E/AndroidRuntime(5554):     ... 11 more
02-07 13:16:55.797: I/Process(5554): Sending signal. PID: 5554 SIG: 9

Has anyone ran into similar problems or know the solution? 有没有人遇到类似的问题或知道解决方案?

The App crashes because it cant find the ImageGridActivity . 该应用程序崩溃,因为它找不到ImageGridActivity Check your package name in the manifest and the Activity name also manifest检查您的包名称,并检查Activity name

Eclipse gets a few things wrong during this import, and you need to fix it manually. Eclipse在此导入过程中出错了一些,您需要手动对其进行修复。

  1. After the import, you will notice that there is an error in res/values-v11 . 导入后,您会注意到res/values-v11中存在错误。 To fix this, Go to Project Properties of ImageGridActivity and select Android. 要解决此问题,请转到ImageGridActivity的项目属性,然后选择Android。 Check Android 4.4 (API level 19). 检查Android 4.4(API级别19)。 Then, select Java Build Path. 然后,选择“ Java构建路径”。 In the Order and Export tab, check Android 4.4. 在“订单和导出”标签中,选中“ Android 4.4”。 The error in res/values-v11 should now be fixed and it should build without errors. res/values-v11的错误现在应该已修复,并且应该正确构建。 However, if you try to run the project now, the app will crash with the error described by the OP ( java.lang.ClassNotFoundException ). 但是,如果尝试立即运行项目,则该应用程序将崩溃,并显示OP( java.lang.ClassNotFoundException )描述的错误。

  2. During the import, Eclipse mistakenly creates an empty src directory and adds it as a source folder on the build path. 在导入期间,Eclipse错误地创建了一个空的src目录,并将其添加为构建路径上的源文件夹。 The source files are actually in the java directory, so fix it as follows: Go to Project Properties of ImageGridActivity and select Java Build Path. 源文件实际上位于java目录中,因此请按以下步骤对其进行修复:转到ImageGridActivity的Project Properties,然后选择Java Build Path。 Under the Source tab, add the java folder, and remove the src folder. 在“源”选项卡下,添加java文件夹,然后删除src文件夹。 Almost there, but the app will still crash with the same error if you run it. 快到了,但是如果您运行该应用,它仍然会崩溃并出现相同的错误。

  3. The final step of getting this to work is to add android-support-v4.jar to the build path. android-support-v4.jar起作用的最后一步是将android-support-v4.jar添加到构建路径。 Again, go to Project Properties of ImageGridActivity and select Java Build Path. 再次,转到ImageGridActivity的项目属性,然后选择Java Build Path。 Under the Libraries tab, click Add External JARs... and find that jar file. 在“库”选项卡下,单击“添加外部JAR ...”,然后找到该jar文件。 On my system it is at <home>/Development/adt-bundle-mac-x86_64-20131030/sdk/extras/android/support/v4/android-support-v4.jar . 在我的系统上,它位于<home>/Development/adt-bundle-mac-x86_64-20131030/sdk/extras/android/support/v4/android-support-v4.jar Then, go to the Order and Export tab and check android-support-v4.jar . 然后,转到“订单和导出”标签,然后检查android-support-v4.jar That's it. 而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM