我只在 HTC 设备上遇到了非常奇怪的行为。我的应用程序在除 HTC 设备之外的所有其他设备上 100% 运行。
问题发生在我启动相机意图之后,我弹回以前的布局,然后尝试导航回启动相机意图的活动。我setContentView()
在OnCreate()
.
我已经包括了我的LaunchCameraIntent
和OnActivityResult()
功能。
有人有想法吗?
我在另一个线程上读到,这可能是从活动启动意图时发生的 HTC 特定问题,并且由于某种原因,垃圾收集器被调用以清除该活动,因此在尝试返回时会导致空引用错误。
这是线程
http://mono-for-android.1047100.n5.nabble.com/Crash-on-HTC-td5710360.html
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
this.SetContentView (Resource.Layout.PhotoAccidentCarLayout);
}
private void LaunchCameraIntent (int picType)
{
Intent intent = new Intent(Android.Provider.MediaStore.ActionImageCapture);
MDCarPicStatus.PicUri = ContentResolver.Insert (isMounted ? Android.Provider.MediaStore.Images.Media.ExternalContentUri : Android.Provider.MediaStore.Images.Media.InternalContentUri, new ContentValues ());
intent.PutExtra (Android.Provider.MediaStore.ExtraOutput, MDCarPicStatus.PicUri);
intent.PutExtra ("isCamera", true);
MDCameraHelper.isCamera = true;
StartActivityForResult (intent, picType);
}
protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
if ((resultCode == Result.Ok)) {
if (data == null) {
SaveImage (MDCarPicStatus.PicUri, (PhotoType)requestCode);
} else {
if (data.Data == null) {
SaveImage (MDCarPicStatus.PicUri, (PhotoType)requestCode);
} else {
SaveImage (data.Data, (PhotoType)requestCode);
}
}
}
base.OnActivityResult (requestCode, resultCode, data);
}
这是我的堆栈跟踪
System.NullReferenceException: Object reference not set to an instance of an object
at (wrapper delegate-invoke) <Module>.invoke_void__this___intptr_intptr_intptr_intptr_JValue[] (intptr,intptr,intptr,intptr,Android.Runtime.JValue[]) <IL 0x00062, 0x00153>
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00000] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.6-branch/632e6ddf/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:612
at Android.App.Activity.SetContentView (int) [0x0006b] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.6-branch/632e6ddf/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:3119
at CCIC.MD.PhotoAccidentCarActivity.OnCreate (Android.OS.Bundle) [0x00009] in c:\Work\Sepia\Source\mobipro02.exordia.co.za\CCIC\trunk\CCIC.MD\CCIC.MD\Activities\Claim\PhotoAccidentCarActivity.cs:41
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-mac-monodroid-4.2.6-branch/632e6ddf/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:1490
at (wrapper dynamic-method) object.2b7db9d6-0abc-4175-b134-cda100e112d6 (intptr,intptr,intptr) <IL 0x00012, 0x00033>
有人知道吗?谢谢你。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/SecondaryAndroidBackgroundNoLogo"
android:minWidth="25px"
android:minHeight="25px">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayout1"
android:minWidth="25px"
android:minHeight="25px">
<RelativeLayout
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/relativeLayout1"
android:layout_height="match_parent"
android:layout_width="match_parent">
<TableLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tableLayout2"
android:layout_centerInParent="true">
<TableRow
android:id="@+id/tableRow2">
<TableLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_column="0"
android:id="@+id/tableLayout3">
<TableRow
android:id="@+id/tableRow5"
android:layout_gravity="center"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:text="Front Left"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_gravity="center"
android:layout_column="0"
android:id="@+id/textView44"
android:textColor="#ff003508" />
</TableRow>
<TableRow
android:id="@+id/tableRow6"
android:minWidth="25px"
android:minHeight="25px">
<ImageView
android:id="@+id/btnFrontLeftCamera"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:scaleType="fitCenter"
android:src="@drawable/AndroidCameraImage" />
</TableRow>
</TableLayout>
<TableLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_column="2"
android:id="@+id/tableLayout4">
<TableRow
android:id="@+id/tableRow7"
android:layout_gravity="center"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:text="Front Right"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_column="0"
android:id="@+id/textView44"
android:textColor="#ff003508" />
</TableRow>
<TableRow
android:id="@+id/tableRow8"
android:minWidth="25px"
android:minHeight="25px">
<ImageView
android:id="@+id/btnFrontRightCamera"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:scaleType="center"
android:src="@drawable/AndroidCameraImage" />
</TableRow>
</TableLayout>
</TableRow>
<TableRow
android:id="@+id/tableRow3">
<TableLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_column="0"
android:id="@+id/tableLayout6"
android:layout_gravity="center">
<TableRow
android:id="@+id/tableRow12"
android:layout_gravity="center"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:text="Left Side"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_column="0"
android:id="@+id/textView44"
android:textColor="#ff003508" />
</TableRow>
<TableRow
android:id="@+id/tableRow13"
android:minWidth="25px"
android:minHeight="25px">
<ImageView
android:id="@+id/btnLeftSideCamera"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:layout_column="0"
android:scaleType="center"
android:src="@drawable/AndroidCameraImage" />
</TableRow>
</TableLayout>
<ImageView
android:id="@+id/imageView6"
android:layout_width="100sp"
android:layout_height="250sp"
android:layout_column="1"
android:scaleType="centerInside"
android:src="@drawable/AndroidCarAlone" />
<TableLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_column="2"
android:id="@+id/tableLayout5"
android:layout_gravity="center">
<TableRow
android:id="@+id/tableRow9"
android:layout_gravity="center"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:text="Right Side"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_column="0"
android:id="@+id/textView44"
android:textColor="#ff003508" />
</TableRow>
<TableRow
android:id="@+id/tableRow10"
android:minWidth="25px"
android:minHeight="25px">
<ImageView
android:id="@+id/btnRightSideCamera"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:scaleType="center"
android:src="@drawable/AndroidCameraImage" />
</TableRow>
</TableLayout>
</TableRow>
<TableRow
android:id="@+id/tableRow4">
<TableLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_column="0"
android:id="@+id/tableLayout7">
<TableRow
android:id="@+id/tableRow14"
android:layout_gravity="center"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:text="Back Left"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_column="0"
android:id="@+id/textView44"
android:textColor="#ff003a03" />
</TableRow>
<TableRow
android:id="@+id/tableRow15"
android:minWidth="25px"
android:minHeight="25px">
<ImageView
android:id="@+id/btnBackLeftCamera"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:layout_column="0"
android:scaleType="center"
android:src="@drawable/AndroidCameraImage" />
</TableRow>
</TableLayout>
<TableLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_column="2"
android:id="@+id/tableLayout8">
<TableRow
android:id="@+id/tableRow16"
android:layout_gravity="center"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:text="Back Right"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_column="0"
android:id="@+id/textView44"
android:textColor="#ff003a03" />
</TableRow>
<TableRow
android:id="@+id/tableRow17"
android:minWidth="25px"
android:minHeight="25px">
<ImageView
android:id="@+id/btnBackRightCamera"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:scaleType="center"
android:src="@drawable/AndroidCameraImage" />
</TableRow>
</TableLayout>
</TableRow>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="80sp"
android:id="@+id/linearLayout1"
android:minWidth="25px"
android:minHeight="25px"/>
</TableLayout>
</RelativeLayout>