嘿,这是我遇到过的最奇怪的问题,我有 2 个项目在不同的项目中完全相同,每个项目具有不同的包名称。
现在我正在尝试运行第二个项目并且我得到一个 NullPointerException 并且当我按下错误以将我发送到代码行时,它会加载相同的活动但在不同的项目中。
知道为什么会这样吗?
这是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="shibby.koteret"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<activity
android:name=".TenKoteretActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="@string/chosen_image" android:name="selectedImageActivity"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait"
/>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>
除了包名称和主要活动名称之外,这在两个项目中完全相同。
这是日志猫:
06-26 21:02:38.324: E/AndroidRuntime(5237): FATAL EXCEPTION: main
06-26 21:02:38.324: E/AndroidRuntime(5237): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1886, result=-1, data=Intent { dat=content://media/external/images/media/45 }} to activity {shibby.koteret/shibby.koteret.selectedImageActivity}: java.lang.NullPointerException
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.app.ActivityThread.access$2000(ActivityThread.java:117)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:965)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.os.Looper.loop(Looper.java:123)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.app.ActivityThread.main(ActivityThread.java:3687)
06-26 21:02:38.324: E/AndroidRuntime(5237): at java.lang.reflect.Method.invokeNative(Native Method)
06-26 21:02:38.324: E/AndroidRuntime(5237): at java.lang.reflect.Method.invoke(Method.java:507)
06-26 21:02:38.324: E/AndroidRuntime(5237): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
06-26 21:02:38.324: E/AndroidRuntime(5237): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
06-26 21:02:38.324: E/AndroidRuntime(5237): at dalvik.system.NativeStart.main(Native Method)
06-26 21:02:38.324: E/AndroidRuntime(5237): Caused by: java.lang.NullPointerException
06-26 21:02:38.324: E/AndroidRuntime(5237): at shibby.koteret.selectedImageActivity.onActivityResult(selectedImageActivity.java:196)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.app.Activity.dispatchActivityResult(Activity.java:3908)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
06-26 21:02:38.324: E/AndroidRuntime(5237): ... 11 more
我不认为这是相关的,但正如所问的那样,这是相关的 Java 代码(setContentView 上的错误):
setContentView(R.layout.chosen_image);
ImageView imageView = (ImageView)this.findViewById(R.id.chosenImage2);
imageView.setImageBitmap(bitmap);
我检查过的内容:
- 第二个项目将活动打包到写项目
- 我没有从第一个项目包中导入任何东西
这可能只是一个 Eclipse 错误吗?有人见过这样的问题吗?
我在想,由于错误在 XML 文件上,它可能与 R 有某种关系吗?