android.view.WindowManager$BadTokenException: Unable to add window - android

I'm adding popup window in fragment when a user clicks on floating action button, in popup window I have added AutoComplete Edit field when I clicked the floating action button, the popup window shows successfully but when I click the edit field it gave an error.
The error is
Here is complete error.
Process: com.example.mubtadanaqvi.stunexus, PID: 7252
android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W#4234e238 is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:769)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:278)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.widget.PopupWindow.invokePopup(PopupWindow.java:1067)
at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:966)
at android.widget.ListPopupWindow.show(ListPopupWindow.java:635)
at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1119)
at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:973) at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:955)
at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:548)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Here is my code
floatingActionButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View customView = inflater.inflate(R.layout.add_new_skill, null);
mPopupWindow = new PopupWindow(
customView,
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
true
);
ImageButton cancel = (ImageButton) customView.findViewById(R.id.close_button);
cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mPopupWindow.dismiss();
}
});
skillListAdapter = new ArrayAdapter<>(getContext(),android.R.layout.simple_dropdown_item_1line, skillsList);
skillInputField = (AutoCompleteTextView) customView.findViewById(R.id.skill_input);
skillInputField.setThreshold(1);
skillInputField.setAdapter(skillListAdapter);
skillListAdapter.addAll(skillsList);
skillListAdapter.notifyDataSetChanged();
Button saveButton = (Button) customView.findViewById(R.id.save_skill);
saveButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String skillText = skillInputField.getText().toString();
if (skillText.isEmpty())
makeToast("EMPTY");
else {
if (ConnectivityListener.isNetwork(getContext())) {
// progressDialog.show();
mPopupWindow.dismiss();
makeToast(skillText);
list.add(new Skill_Item(skillText, 0));
adapter.notifyDataSetChanged();
} else
makeToast("connection error!");
}
}
});
mPopupWindow.showAtLocation(rootLayout, Gravity.CENTER, 0, 0);
}
});

Reason of Exception:
Activity has finished but you are trying to display a dialog with a context of the finished activity. Since there is no window for the dialog to display the android runtime throws this exception.
Solution of Exception:
Please use isFinishing() method which is called by Android to check whether this activity is in the process of finishing:
private final WeakReference<MainActivity> mainActivityWeakRef;
mainActivityWeakRef =new WeakReference<MainActivity>(this);
if (mainActivityWeakRef.get() != null && !mainActivityWeakRef.get().isFinishing()) {
// Your Code
}

Related

crash after dialog dismiss in android

I have the following crash
java.lang.IllegalArgumentException: View=DecorView#62c59a[] not attached to window manager
at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:473)
at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:382)
at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:128)
at android.app.Dialog.dismissDialog(Dialog.java:727)
at android.app.Dialog.-android_app_Dialog-mthref-0(Dialog.java:167)
at android.app.Dialog$-void__init__android_content_Context_context_int_themeResId_boolean_createContextThemeWrapper_LambdaImpl0.run(Dialog.java)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
can anyone please help and tell me what cause this crash and how to solve it ?
EDIT
this is the method that show the dialog
public static void showDialogMessage(Activity activity, String title,
String message, String buttonString, final OnClickListener listener) {
try {
final Dialog dialog = new Dialog(activity);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_error_message_layout);
dialog.setCancelable(false);
TextView titleTV = (TextView) dialog.findViewById(R.id.title_textview);
TextView descriptionTV = (TextView) dialog
.findViewById(R.id.description_textview);
Button okButton = (Button) dialog.findViewById(R.id.ok_button);
Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button);
titleTV.setText(title);
descriptionTV.setText(message);
okButton.setText(buttonString);
cancelButton.setVisibility(View.GONE);
okButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
if (listener != null)
listener.onClick(null);
}
});
dialog.getWindow().setBackgroundDrawableResource(
android.R.color.transparent);
dialog.show();
} catch (BadTokenException exception) {
exception.printStackTrace();
}
}
The error occurs when Activity gets finished before dialog successfully dismisses. So the Dialog's view is not attached to the windowManager.
Add this check before dismissing the Dialog:
if (!activity.this.isFinishing() && dialog != null) {
dialog.dismiss();
}
Alternatively you can dismiss your dialog in onPause() or onDestroy() of the activity.
#Override
public void onPause() {
super.onPause();
if ((dialog != null) && dialog.isShowing())
dialog.dismiss();
dialog = null;
}

Activity is still showing leaked window which is already handled

I am getting a window leak when I am starting a free walk activity. I have handled that scenario but still don't understand why I am still getting.
Here is my code:
private void showPopUp() {
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before
dialog.setContentView(R.layout.wwmove_screen_popup);
TextView mNo = (TextView) dialog.findViewById(R.id.move_no);
// if button is clicked, close the custom dialog
mNo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
TextView mYes = (TextView) dialog.findViewById(R.id.moveyes);
mYes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
killAll();
storeSegmentcompletdInformation("skipped");
storeOneDayInformation("skipped");
Intent gotoSummary = new Intent(WwFreeWalkMoveActivity.this, WwFreeWalkSummaryActivity.class);
gotoSummary.putExtra(ParamConstants.SUMMARY_GOOGLEFIT_KEY, String.valueOf(stepCountGoogleFit));
startActivity(gotoSummary);
}
});
dialog.show();
}
The error I am getting is:
08-18 10:38:53.172 28118-28118/com.mobiefit.walk E/WindowManager: android.view.WindowLeaked: Activity com.mobiefit.walk.freewalk.activity.WwFreeWalkMoveActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{21f913f9 V.E..... R.....I. 0,0-960,516} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:364)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:274)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.app.Dialog.show(Dialog.java:298)
at com.mobiefit.walk.freewalk.activity.WwFreeWalkMoveActivity.showPopUp(WwFreeWalkMoveActivity.java:953)
at com.mobiefit.walk.freewalk.activity.WwFreeWalkMoveActivity.onOptionsItemSelected(WwFreeWalkMoveActivity.java:1806)
at android.app.Activity.onMenuItemSelected(Activity.java:2936)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:404)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:185)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
at android.support.v7.widget.ToolbarWidgetWrapper$1.onClick(ToolbarWidgetWrapper.java:192)
at android.view.View.performClick(View.java:4785)
at android.view.View$PerformClick.run(View.java:19888)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5273)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
Can anyone tell me what I am doing wrong?
Window leaked exceptions are usually caused by dialogs which are not dismissed properly.
you have to dismiss the dialog
In your code
use this
dialog.dismiss();
mYes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
killAll();
storeSegmentcompletdInformation("skipped");
storeOneDayInformation("skipped");
Intent gotoSummary = new Intent(WwFreeWalkMoveActivity.this, WwFreeWalkSummaryActivity.class);
gotoSummary.putExtra(ParamConstants.SUMMARY_GOOGLEFIT_KEY, String.valueOf(stepCountGoogleFit));
startActivity(gotoSummary);
}
});
Before proceeding to next activity or task. dismiss your dialog.dismiss(); dialog.
public void onClick(View v) {
killAll();
storeSegmentcompletdInformation("skipped");
storeOneDayInformation("skipped");
Intent gotoSummary = new Intent(WwFreeWalkMoveActivity.this, WwFreeWalkSummaryActivity.class);
gotoSummary.putExtra(ParamConstants.SUMMARY_GOOGLEFIT_KEY, String.valueOf(stepCountGoogleFit));
dialog.dismiss(); // here you just have to add one line.
startActivity(gotoSummary);
}

NullPointerException when using database object [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
I'm new to Android, and i've got some issues.
It looks like it's saying DB.EmployeeOperations.open() is having an null object passed to it, but I'm not sure.
Where I missed a step?
Any help is appreciated.
Thanks in advance.
Logcat:
* 06-10 16:10:52.605 17203-17203/com.androidtutorialpoint.employeemanagementsystem E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.androidtutorialpoint.employeemanagementsystem, PID: 17203
java.lang.RuntimeException: Unable to resume activity {com.androidtutorialpoint.employeemanagementsystem/com.androidtutorialpoint.employeemanagementsystem.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.androidtutorialpoint.employeemanagementsystem.DB.EmployeeOperations.open()' on a null object reference
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3019)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3050)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2425)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5294)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.androidtutorialpoint.employeemanagementsystem.DB.EmployeeOperations.open()' on a null object reference
at com.androidtutorialpoint.employeemanagementsystem.MainActivity.onResume(MainActivity.java:148)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1257)
at android.app.Activity.performResume(Activity.java:6076)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3008)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3050)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2425)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
Java Code:
public class MainActivity extends AppCompatActivity{
private Button addEmployeeButton;
private Button editEmployeeButton;
private Button deleteEmployeeButton;
private Button viewAllEmployeeButton;
private EmployeeOperations employeeOps;
private static final String EXTRA_EMP_ID = "com.androidtutorialpoint.empId";
private static final String EXTRA_ADD_UPDATE = "com.androidtutorialpoint.add_update";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addEmployeeButton = (Button) findViewById(R.id.button_add_employee);
editEmployeeButton = (Button) findViewById(R.id.button_edit_employee);
deleteEmployeeButton = (Button) findViewById(R.id.button_delete_employee);
viewAllEmployeeButton = (Button)findViewById(R.id.button_view_employees);
addEmployeeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this,AddUpdateEmployee.class);
i.putExtra(EXTRA_ADD_UPDATE, "Add");
startActivity(i);
}
});
editEmployeeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getEmpIdAndUpdateEmp();
}
});
deleteEmployeeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getEmpIdAndRemoveEmp();
}
});
viewAllEmployeeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, ViewAllEmployees.class);
startActivity(i);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.employee_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.menu_item_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void getEmpIdAndUpdateEmp(){
LayoutInflater li = LayoutInflater.from(this);
View getEmpIdView = li.inflate(R.layout.dialog_get_emp_id, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
// set dialog_get_emp_id.xml to alertdialog builder
alertDialogBuilder.setView(getEmpIdView);
final EditText userInput = (EditText) getEmpIdView.findViewById(R.id.editTextDialogUserInput);
// set dialog message
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// get user input and set it to result
// edit text
Intent i = new Intent(MainActivity.this,AddUpdateEmployee.class);
i.putExtra(EXTRA_ADD_UPDATE, "Update");
i.putExtra(EXTRA_EMP_ID, Long.parseLong(userInput.getText().toString()));
startActivity(i);
}
}).create()
.show();
}
public void getEmpIdAndRemoveEmp(){
LayoutInflater li = LayoutInflater.from(this);
View getEmpIdView = li.inflate(R.layout.dialog_get_emp_id, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
// set dialog_get_emp_id.xml to alertdialog builder
alertDialogBuilder.setView(getEmpIdView);
final EditText userInput = (EditText) getEmpIdView.findViewById(R.id.editTextDialogUserInput);
// set dialog message
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// get user input and set it to result
// edit text
employeeOps = new EmployeeOperations(MainActivity.this);
employeeOps.removeEmployee(employeeOps.getEmployee(Long.parseLong(userInput.getText().toString())));
Toast t = Toast.makeText(MainActivity.this,"Employee removed successfully!",Toast.LENGTH_SHORT);
t.show();
}
}).create()
.show();
}
#Override
protected void onResume() {
super.onResume();
employeeOps.open();
}
#Override
protected void onPause() {
super.onPause();
employeeOps.close();
}
}
The problem is you're calling employeeOps.open() in onResume(), but employeeOps is not instantiated yet, it's value is still null.
Take a look at the Activity lifecycle.
As you can see, when an Activity gets created two methods get called before onResume(): onCreate() and onStart().
If you would like to call the open() method of EmployeeOperations in onResume(), you need to have an instance of it by then.
Call the following in onCreate():
employeeOps = new EmployeeOperations(this);
Your problem is a misunderstanding of the Android lifecycle. Specifically, from that resource,
Once the onCreate() finishes execution, the system calls the onStart() and onResume() methods in quick succession.
What this means for you is that onResume() triggers before you ever set employeeOps to a non-null value. You're only initializing it in response to a button press, but your Activity is only visible for a very short duration before onResume is triggered.

In Android how to call a popup window when a button in another custom popup window is clicked

On clicking a button in my main screen, I have a dialog box opening.
On clicking a button in the dialog box, a pop-up screen opens.The following is the code. This part works fine.
final Dialog dialog = new Dialog(this,R.style.FullHeightDialog);
// dialog box layout is layout.xml
dialog.setContentView(R.layout.layout);
//layout of pop-up window is howtoplay.xml
final LayoutInflater inflater = (LayoutInflater) MainActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View popupView = inflater.inflate(R.layout.howtoplay, null, false);
final PopupWindow pw = new PopupWindow(popupView,400,440, true);
//On clicking button in dialog,popup opens
Button howto = (Button) dialog.findViewById(R.id.rules);
howto.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
pw.setContentView(inflater.inflate(R.layout.howtoplay, null, false));
pw.showAtLocation(v, Gravity.CENTER, 0, 0);
pw.update(0,0,wth*8,ht*10);
Button close = (Button)pw.getContentView().findViewById(R.id.done);
close.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
pw.dismiss();
}
});
}
});
I want to open a pop-up screen(playvideo.xml) when a button in the howtoplay pop-up screen is clicked. The following is the code I've written in the onclicklistener method of the button.
public void howtoplayvideo(View v){
System.out.println("------clicked-------");
final LayoutInflater inflater = (LayoutInflater)MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View popupView = inflater.inflate(R.layout.playvodeo, null, false);
final PopupWindow pw = new PopupWindow(popupView,400,440, true);
pw.setContentView(inflater.inflate(R.layout.playvideo, null, false));
pw.showAtLocation(v, Gravity.CENTER, 0, 0);
pw.update(0,0,wth*8,ht*10);
}
"clicked" is getting printed, but then am getting an exception
Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W#453afa80 is not valid; is your activity running?
Please help me!!
This might be too late but the reason why your code is not working is because the you are saying:
pw.showAtLocation(v, Gravity.CENTER, 0, 0);
The v you have passed in is the view for the howto button and not for your layout view that you want the popupwindow to show on top of.

Error : the specified child already has a parent

I'm trying to keep on creating my application, (to create a list of name when you click on the add button). But I have this exception and i don't succeed in removing it;
That's my code :
mageButton addButton = null;
RelativeLayout menuactivitylayout=null;
int j=0;
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
menuactivitylayout=(RelativeLayout)findViewById(R.id.Relativelayoutacitivtymenu);
addButton = (ImageButton) findViewById(R.id.buttonaddplayer);
addButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Create custom dialog object
final Dialog dialog = new Dialog(MenuActivity.this);
dialog.setTitle(getResources().getString(R.string.addperson));
// Include dialog.xml file
dialog.setContentView(R.layout.dialoglayout);
// Set dialog title
// dialog.setTitle("Custom Dialog");
// set values for custom dialog components - text, image and button
final EditText text = (EditText) dialog.findViewById(R.id.editTextdialog);
dialog.show();
final ImageButton validButton = (ImageButton) dialog.findViewById(R.id.imageButtonvalid);
// if decline button is clicked, close the custom dialog
validButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final LinearLayout ll = new LinearLayout(MenuActivity.this);
ll.setOrientation(LinearLayout.HORIZONTAL);
ImageView person = new ImageView(MenuActivity.this);
person.setImageDrawable(getResources().getDrawable(R.drawable.person));
person.setMaxHeight(50);
person.setMaxWidth(50);
ll.addView(person);
final TextView name = new TextView(MenuActivity.this);
name.setText(text.getText().toString());
ll.addView(name);
final ImageButton edit = new ImageButton(MenuActivity.this);
edit.setId(j+1);
edit.setImageDrawable(getResources().getDrawable(R.drawable.edit));
edit.setLayoutParams(params);
j++;
edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final Dialog editDialog = new Dialog(MenuActivity.this);
editDialog.setTitle("Editer");
dialog.setContentView(R.layout.edtidialoglayout);
final EditText edititextdialog = (EditText) dialog.findViewById(R.id.editTexteditDialog);
dialog.show();
ImageButton validButton = (ImageButton) dialog.findViewById(R.id.imageButtonvalideditdialog);
validButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
name.setText(edititextdialog.getText().toString());
dialog.dismiss();
}
});
}
});
ll.addView(validButton);
menuactivitylayout.addView(ll);
dialog.dismiss();
}
});
This is the logcat
01-31 22:33:49.587 20692-20692/com.example.guillaume.drinkwithfriends E/AndroidRuntime﹕ FATAL EXCEPTION: main
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:3439)
at android.view.ViewGroup.addView(ViewGroup.java:3310)
at android.view.ViewGroup.addView(ViewGroup.java:3255)
at android.view.ViewGroup.addView(ViewGroup.java:3231)
at com.example.guillaume.drinkwithfriends.MenuActivity$1$1.onClick(MenuActivity.java:107)
at android.view.View.performClick(View.java:4162)
at android.view.View$PerformClick.run(View.java:17082)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
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:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
I have understood that ll has dialog for parents, but i don't succed in removing it !
I know that using a Listview with an inflater and an adapter would be better, but i'm a beginner and i don't really understand what is "Inflater" and "Adapter" ..
Thank you very much
This is line that must be causing the problem.
ll.addView(validButton);
you can't add validButton to the layout because it is already in the dialog box which means it has a parent.
Remove this line and see if it works.

Categories

Resources