指定的孩子已经在谷歌闹钟code父 [英] The specified child already has a parent in google alarmclock code
问题描述
我修改了一些谷歌code为我的当前项目。我刚开始在这个类,这是令人费解,因为我已经不是人工做这一类的任何更改得到一个错误。
下面的错误:
致命异常:主要
了java.lang.RuntimeException:无法启动活动ComponentInfo {com.skipmorrow.powerclock / com.skipmorrow.powerclock.SetAlarm}:java.lang.IllegalStateException:指定的小孩已经有一个父。您必须先对孩子的父母打电话removeView()。
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2304)
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2354)
在android.app.ActivityThread.access $ 600(ActivityThread.java:150)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1244)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:5191)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:795)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
在dalvik.system.NativeStart.main(本机方法)
java.lang.IllegalStateException:引起指定的小孩已经有一个父。您必须先对孩子的父母打电话removeView()。
在android.view.ViewGroup.addViewInner(ViewGroup.java:3339)
在android.view.ViewGroup.addView(ViewGroup.java:3210)
在android.view.ViewGroup.addView(ViewGroup.java:3186)
在com.skipmorrow.powerclock.SetAlarm.onCreate(SetAlarm.java:134)
在android.app.Activity.performCreate(Activity.java:5104)
在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2258)
和这里的code。就像我说的,我还没有做出任何变化,我不认为有必要使基于我的项目要求的任何变化。我讨厌在那里去摆弄东西,如果它是没有必要的。整个项目可在这里:
https://github.com/android/platform_packages_apps_alarmclock
我的编译API 8。
//获取主ListView和从内容视图中删除它。
ListView控件LV = getListView();
content.removeView(LV); //创建新的LinearLayout将成为内容和观点
//使其垂直。
LL的LinearLayout =新的LinearLayout(本);
ll.setOrientation(LinearLayout.VERTICAL); //有ListView的扩展以填充屏幕减去保存/取消
// 纽扣。
LinearLayout.LayoutParams LP =新LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
lp.weight = 1;
ll.addView(LV,LP); //错误在这里。 134行
您可以尝试直接从视图获取父,这样你就没有问题。
您
//获取主ListView和从内容视图中删除它。
ListView控件LV = getListView();
content.removeView(LV);
您就需要将其更改为
//获取主ListView和从内容视图中删除它。
ListView控件LV = getListView();
((ViewGroup中)lv.getParent())removeView(LV)。
I am modifying some google code for my current project. I just started getting an error in this class, which is puzzling because I haven't made any changes to this class at all.
Here's the error:
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)
And here's the code. Like I said, I haven't made any changes to it, and I don't see the need to make any changes to it based on my project requirements. I hate to go in there mucking things up if it isn't necessary. The entire project is available here: https://github.com/android/platform_packages_apps_alarmclock
I am compiling for 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
You could try to get the parent directly from the view so you don't have the problem.
You have
// Get the main ListView and remove it from the content view.
ListView lv = getListView();
content.removeView(lv);
You'd need to change it to
// Get the main ListView and remove it from the content view.
ListView lv = getListView();
((ViewGroup)lv.getParent()).removeView(lv);
这篇关于指定的孩子已经在谷歌闹钟code父的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!