在我的Android应用程序中,我使用了碎片,并将片段置于片段活动之上。当我更改方向时,它会强制关闭并且日志cat错误就像这样。
我不明白什么是错的,所以任何人都可以指导我解决问题。以下是总代码& logcat错误。
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
// this is really important in order to save the state across screen
// configuration changes for example
}
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
System.out.println("oncreate");
// Retain this instance so it isn't destroyed when MainActivity and
// MainFragment change configuration.
setRetainInstance(true);
preferences = getActivity().getSharedPreferences("Preferences", 0);
editor = preferences.edit();
displayViewPreferences = getActivity().getSharedPreferences("View_Prerferences", 0);
String displayViewString = displayViewPreferences.getString("View_Prerferences", "AlarmTag");
if(savedInstanceState!= null)
{
if(displayViewString.equals("OffsetTag"))
{
AlarmFragment mAlarmFragment = new AlarmFragment();
getFragmentManager().beginTransaction().replace(R.id.holder_fragment, mAlarmOffsetFragment).commit();
}else
{
System.out.println("PaiSensor: Display VIew Tag Is== NULL");
}
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
view =inflater.inflate(R.layout.alarm_offset_fragment,null);
mSensorTextView = (TextView)view.findViewById(R.id.tv_Offset_Sensor);
mSensorTypeTextView = (TextView)view.findViewById(R.id.tv_alarmOffset_sensorType);
mHigh = (EditText)view.findViewById(R.id.et_Offset_high);
mLow = (EditText)view.findViewById(R.id.et_Offset_low);
mAlarmDeadBand = (EditText)view.findViewById(R.id.et_alarmOffset_alarmDeadband);
mOffsetCorrection = (EditText)view.findViewById(R.id.et_offsetCorrection);
/**
* Gets the data from Shared Preferences
*/
mPairedSensorTextView.setText(preferences.getString("Sensor", ""));
mSensorTypeTextView.setText(preferences.getString("Type", ""));
return view;
}
@Override
public void onDestroyView() {
// TODO Auto-generated method stub
super.onDestroyView();
view = null;
}
03-18 16:37:02.193: E/dalvikvm(28701): Out of memory: Heap Size=131079KB, Allocated=126602KB, Limit=131072KB
03-18 16:37:02.193: E/dalvikvm(28701): Extra info: Footprint=130311KB, Allowed Footprint=131079KB, Trimmed=2712KB
03-18 16:37:02.193: D/skia(28701): --- Unable to allocate space, reportSizeToVM = true
03-18 16:37:02.193: W/dalvikvm(28701): threadid=1: thread exiting with uncaught exception (group=0x40f4f468)
03-18 16:37:02.203: E/AndroidRuntime(28701): FATAL EXCEPTION: main
03-18 16:37:02.203: E/AndroidRuntime(28701): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.uwbt.ui/com.uwbt.ui.UWBTActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2355)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4085)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.app.ActivityThread.access$700(ActivityThread.java:151)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.os.Looper.loop(Looper.java:155)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.app.ActivityThread.main(ActivityThread.java:5511)
03-18 16:37:02.203: E/AndroidRuntime(28701): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 16:37:02.203: E/AndroidRuntime(28701): at java.lang.reflect.Method.invoke(Method.java:511)
03-18 16:37:02.203: E/AndroidRuntime(28701): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
03-18 16:37:02.203: E/AndroidRuntime(28701): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
03-18 16:37:02.203: E/AndroidRuntime(28701): at dalvik.system.NativeStart.main(Native Method)
03-18 16:37:02.203: E/AndroidRuntime(28701): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
03-18 16:37:02.203: E/AndroidRuntime(28701): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-18 16:37:02.203: E/AndroidRuntime(28701): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:369)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.app.Activity.setContentView(Activity.java:1912)
03-18 16:37:02.203: E/AndroidRuntime(28701): at com.uwbt.ui.UWBTActivity.onCreate(UWBTActivity.java:126)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.app.Activity.performCreate(Activity.java:5066)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
03-18 16:37:02.203: E/AndroidRuntime(28701): ... 12 more
03-18 16:37:02.203: E/AndroidRuntime(28701): Caused by: java.lang.reflect.InvocationTargetException
03-18 16:37:02.203: E/AndroidRuntime(28701): at java.lang.reflect.Constructor.constructNative(Native Method)
03-18 16:37:02.203: E/AndroidRuntime(28701): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-18 16:37:02.203: E/AndroidRuntime(28701): ... 24 more
03-18 16:37:02.203: E/AndroidRuntime(28701): Caused by: java.lang.OutOfMemoryError: (Heap Size=131079KB, Allocated=126602KB)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:626)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:473)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.content.res.Resources.loadDrawable(Resources.java:1959)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.view.View.<init>(View.java:3354)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.view.View.<init>(View.java:3291)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.view.ViewGroup.<init>(ViewGroup.java:432)
03-18 16:37:02.203: E/AndroidRuntime(28701): at android.widget.RelativeLayout.<init>(RelativeLayout.java:184)
03-18 16:37:02.203: E/AndroidRuntime(28701): ... 27 more