my code is here
if(c!=null)
{
c.moveToFirst();
String col = c.getString(2); //
check.setText(col);
check.setVisibility(0);
while(!c.isAfterLast())
{
String col1 = c.getString(1);
String col2 = c.getString(2);
String col3 = c.getString(3);
while(!c.isAfterLast())
{
TextView que1 = new TextView(this);
que1.setText(col1);
lymn.addView(que1);
if(col3.equals("Date"))
{
DatePicker dp = new DatePicker(this);
lymn.addView(dp);
break;
}
if(col3.equals("User Input"))
{
EditText ed = new EditText(this);
ed.setWidth(250);
lymn.addView(ed);
break;
}
if(col3.equals("YES/NO"))
{
yes1.setText("Yes");
no1.setText("NO");
rg1.addView(yes1);
rg1.addView(no1);
lymn.addView(rg1);
break;
}
if(col3.equals("High Average Low"))
{
High1.setText("High");
Avg1.setText("Average");
Low1.setText("Low");
rg2.addView(High1);
rg2.addView(Avg1);
rg2.addView(Low1);
lymn.addView(rg2);
break;
}
if(col3.equals("Excellent Good Average Poor"))
{
exce1.setText("Excellent");
good1.setText("Good");
avg11.setText("Average");
poor1.setText("Poor");
rg3.addView(exce1);
rg3.addView(good1);
rg3.addView(avg11);
rg3.addView(poor1);
lymn.addView(rg3);
break;
}
break;
}
c.moveToNext();
}
}
when i run this code igot error like this
09-06 11:34:37.777: WARN/Exception(27814): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
09-06 11:34:37.777: WARN/Exception(27814): at android.view.ViewGroup.addViewInner(ViewGroup.java:1970)
09-06 11:34:37.777: WARN/Exception(27814): at android.view.ViewGroup.addView(ViewGroup.java:1865)
09-06 11:34:37.777: WARN/Exception(27814): at android.view.ViewGroup.addView(ViewGroup.java:1822)
09-06 11:34:37.777: WARN/Exception(27814): at android.view.ViewGroup.addView(ViewGroup.java:1802)
09-06 11:34:37.777: WARN/Exception(27814): at com.ezee.app.user1.LoadCheckIn(user1.java:256)
09-06 11:34:37.777: WARN/Exception(27814): at com.ezee.app.user1.onCreate(user1.java:61)
09-06 11:34:37.777: WARN/Exception(27814): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-06 11:34:37.777: WARN/Exception(27814): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-06 11:34:37.777: WARN/Exception(27814): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-06 11:34:37.777: WARN/Exception(27814): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-06 11:34:37.777: WARN/Exception(27814): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-06 11:34:37.777: WARN/Exception(27814): at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 11:34:37.777: WARN/Exception(27814): at android.os.Looper.loop(Looper.java:123)
09-06 11:34:37.777: WARN/Exception(27814): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-06 11:34:37.777: WARN/Exception(27814): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 11:34:37.777: WARN/Exception(27814): at java.lang.reflect.Method.invoke(Method.java:521)
09-06 11:34:37.777: WARN/Exception(27814): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-06 11:34:37.777: WARN/Exception(27814): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-06 11:34:37.777: WARN/Exception(27814): at dalvik.system.NativeStart.main(Native Method)
plz help me on this
The error you are getting is hard to find because your code is all over the place, but the error means you are adding a
View(child) that is allready on the screen (has a parent).This could be anywhere, hard to say with this post, but for example:
This one probably works:
edis new, so doesn’t have a parent.But I can’t find the declaration of
yes1, so this one MIGHT be the culprint. Or maybeno1.Check all your
addViewcalls. (hint: there is a line-number in that error somewhere. use it)To try to answer your question in the comment, you must follow these rules;
findViewById, don’t useaddViewon it.addViewwith a NEW view.addView.And, I can’t stress this more: find out, using the line-number in the error, which line produces the error. Look at what you are adding there, and try to figure out with above help why that doesn’t work.