I am trying to create a very simple dialog, triggered by clicking a
button. Seems that no matter what I do, I get this error:
java.lang.IllegalStateException: The specified child already has a
parent. You must call removeView() on the child's parent.
I've reduced the java down to this:
@Override
protected Dialog onCreateDialog(int id) {
switch(id) {
case X_OFFSET_D:
LayoutInflater inflater=(LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View
layout=inflater.inflate(R.layout.fractionpicker,
(ViewGroup) findViewById(R.id.root));
AlertDialog.Builder builder=new
AlertDialog.Builder(this);
builder.setView(layout);
builder.setTitle(getResources().getString(R.string.x_offset_change));
builder.setNegativeButton(getResources().getString(R.string.Cancel),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int
whichButton) {
GraphSettings.this.removeDialog(X_OFFSET_D);
}
});
trace("negative button has been set");
builder.setPositiveButton(getResources().getString(R.string.set), new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int
whichButton) {
//TODO handle the updates
GraphSettings.this.removeDialog(X_OFFSET_D);
}
});
AlertDialog xOffsetDialog=builder.create();
return xOffsetDialog;
}
return null;
}
,,,and for now this is all that's left of fractionpicker (referred to
in as an argument in inflater.inflate()) is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"/>
...but I'm still getting that error. Here's the stack trace:
01-14 16:57:21.772: WARN/dalvikvm(209): threadid=3: thread exiting
with uncaught exception (group=0x4001b188)
01-14 16:57:21.772: ERROR/AndroidRuntime(209): Uncaught handler:
thread main exiting due to uncaught exception
01-14 16:57:21.801: ERROR/AndroidRuntime(209):
java.lang.IllegalStateException: The specified child already has a
parent. You must call removeView() on the child's parent first.
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.view.ViewGroup.addViewInner(ViewGroup.java:1861)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.view.ViewGroup.addView(ViewGroup.java:1756)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.view.ViewGroup.addView(ViewGroup.java:1736)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
com.android.internal.app.AlertController.setupView(AlertController.java:
364)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
com.android.internal.app.AlertController.installContent(AlertController.java:
205)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.app.AlertDialog.onCreate(AlertDialog.java:251)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.app.Dialog.dispatchOnCreate(Dialog.java:308)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.app.Activity.createDialog(Activity.java:874)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.app.Activity.showDialog(Activity.java:2483)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
com.oneInfinity.rainOrSine.GraphSettings$1.onClick(GraphSettings.java:
47)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.view.View.performClick(View.java:2364)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.view.View.onTouchEvent(View.java:4179)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.widget.TextView.onTouchEvent(TextView.java:6541)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.view.View.dispatchTouchEvent(View.java:3709)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
com.android.internal.policy.impl.PhoneWindow
$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:
1107)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.app.Activity.dispatchTouchEvent(Activity.java:2061)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
com.android.internal.policy.impl.PhoneWindow
$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.os.Handler.dispatchMessage(Handler.java:99)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.os.Looper.loop(Looper.java:123)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
android.app.ActivityThread.main(ActivityThread.java:4363)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
java.lang.reflect.Method.invokeNative(Native Method)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
java.lang.reflect.Method.invoke(Method.java:521)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-14 16:57:21.801: ERROR/AndroidRuntime(209): at
dalvik.system.NativeStart.main(Native Method)
What am I forgetting here?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en