1
我正在修改當前項目的一些Google代碼。我剛開始在這堂課中發現一個錯誤,這令人費解,因爲我根本沒有對這堂課做任何改變。指定的孩子已經在谷歌鬧鐘代碼中有父母
這裏的錯誤:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.skipmorrow.powerclock/com.skipmorrow.powerclock.SetAlarm}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2304)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2354)
at android.app.ActivityThread.access$600(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5191)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:3339)
at android.view.ViewGroup.addView(ViewGroup.java:3210)
at android.view.ViewGroup.addView(ViewGroup.java:3186)
at com.skipmorrow.powerclock.SetAlarm.onCreate(SetAlarm.java:134)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2258)
而這裏的代碼。就像我說的,我沒有對它做任何改變,我不認爲需要根據我的項目要求對它進行任何更改。如果沒有必要,我討厭在那裏把東西弄糟。整個項目可以在這裏找到: https://github.com/android/platform_packages_apps_alarmclock
我一種編譯API 8
// Get the main ListView and remove it from the content view.
ListView lv = getListView();
content.removeView(lv);
// Create the new LinearLayout that will become the content view and
// make it vertical.
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
// Have the ListView expand to fill the screen minus the save/cancel
// buttons.
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
lp.weight = 1;
ll.addView(lv, lp); // error here. Line 134
問題解決了。奇怪的是,簡單的東西實際上是在谷歌代碼中。哦,好的,謝謝! – MrGibbage 2013-03-04 02:24:49