1

Problem: application crashes with StackOverflowError

ViewRoot.draw(boolean) line: 1374   
ViewRoot.performTraversals() line: 1114 
ViewRoot.handleMessage(Message) line: 1633  
ViewRoot(Handler).dispatchMessage(Message) line: 99 
Looper.loop() line: 123 

I have a TabActivity with some tabs. I add tabs like this:

intent = new Intent().setClass(this, SigninActivity.class);
spec = tabHost.newTabSpec("Signin").setIndicator("CV", res.getDrawable(R.drawable.ic_tab_signin)).setContent(intent);
tabHost.addTab(spec);

In the tab I have, on click I show a pop-up with two buttons from Android popup window dismissal When clicking on some button in popup, language changes like this:

Locale mLocale = new Locale("ar");
Locale.setDefault(mLocale);
Configuration config = getBaseContext().getResources().getConfiguration();
if (!config.locale.equals(mLocale)) {
    config.locale = mLocale;
    getBaseContext().getResources().updateConfiguration(config, null);
    replaceContentView("Signin", new Intent(NewAccActivity.this, NewAccActivity.class));
}

And when I click 6-7 times in one tab to change the language (layout and values), the application crashes with a NullPointer on method (PopupWindow)this.window.dismiss() in popup.

I added a timer for calling dismiss(), but now application crashes with StackOverflowError after 6-7 language changes.

Where is the problem?

Upd: I remove timer. In popup screen all buttons have one OnClickListener.

In activity:

    Button btnDialogShow = (Button) findViewById(R.id.button);
    btnDialogShow.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dw = new LanguageChangeDialog(v, getBaseContext());
            dw.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Button b = (Button) v;
                    switch (b.getId()) {
                    case R.id.en:
                        cvitchToEn();
                        break;
                    case R.id.ar:
                        cvitchToAr();
                        break;
                    }
                }
            });
            dw.showLikePopDownMenu();
        }
    });

If it looks like this, were this.onClickListener external ClickListener in Activity, witch change locale:

public void setOnClickListener(OnClickListener onClickListener) {
    this.onClickListener = onClickListener;
}

public void onClick(final View v) {
    onClickListener.onClick(v);
    dismiss();
}

After click I have exception:

Thread [<3> main] (Suspended (exception NullPointerException))  
    PopupWindow$1.onScrollChanged() line: 124   
    ViewTreeObserver.dispatchOnScrollChanged() line: 607    
    ViewRoot.draw(boolean) line: 1195   
    ViewRoot.performTraversals() line: 1114 
    ViewRoot.handleMessage(Message) line: 1633  
    ViewRoot(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 123 

If I change onClick (another order) like:

public void onClick(final View v) {
    dismiss();
    onClickListener.onClick(v);
}

It works, but after 6-7 click, i have:

Thread [<3> main] (Suspended (exception StackOverflowError))    
    ViewRoot.draw(boolean) line: 1374   
    ViewRoot.performTraversals() line: 1114 
    ViewRoot.handleMessage(Message) line: 1633  
    ViewRoot(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 123 

Bug here somewhere, but I can not understand where.

Community
  • 1
  • 1
anber
  • 3,463
  • 6
  • 39
  • 68

1 Answers1

0

I think the problem is that after changing the locale configuration of the app, the popup window is invalid.

Instead of timer check for null, try checking this.window

lucian.pantelimon
  • 3,673
  • 4
  • 29
  • 46
Alex Klimashevsky
  • 2,457
  • 3
  • 26
  • 58