Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 37
Registered: ‎10-15-2010
My Device: Not Specified

Re: Selecting a different Tab

tx for your replay. I think, i am getting closer...

 

No w i am getting error on

 

this == tabArea.getManager(); 

 

I tried with

 

this.getManager() == tabArea.getManager();

 

I am still getting error....i know this should be easy to do.....but i am not getting this??

 

could you suggest me anything??

 

Could post the link of the delete manager documentation please??

 

 

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Selecting a different Tab

Oh, I see you've skipped an important step or two in your BlackBerry programming:

 

Here is the link (it is for the latest, 6.0.0 API, but Manager.delete() and Field.getManager() did not change much in the last... forever) - make sure you check the API documentation before asking questions here:

BlackBerry 6.0.0 API

I tend to have this page open in a separate tab at work at all times - it's that important!

 

There is a sticky thread in this forum with useful links for novice and experienced programmers alike - check that, too.

 

After you've done some studying, remember that you can search the forums before posting your question - I've found enough useful information that way.

 

By the way, this getManager() is logically wrong - you want to compare the tabArea's manager to this because it is the manager which is trying to delete tabArea.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 37
Registered: ‎10-15-2010
My Device: Not Specified

Re: Selecting a different Tab

[ Edited ]

tx for the quick response,

 

i understood that....

 

when we say this ....  we refrerring to the screen below manager right?

 

this (MainScreen)  == tabArea.getManger() (Manager)  so ....I am getting incomparable type error....

 

 

 

 

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Selecting a different Tab

Oops... if this is a Screen, you need to compare like this:

getDelegate() == tabArea.getManager() // (in case of FullScreen and other Screens)

  or this:

getMainManager() == tabArea.getManager() // (in case of MainScreen)

 

You could also do the whole thing this way:

try {

  delete(tabArea);

} catch (Exception e) {

  // might want to report it - System.out.println(e.toString() + " trying to switch tabs");

}

tabArea = ...;

add(tabArea);

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 37
Registered: ‎10-15-2010
My Device: Not Specified

Re: Selecting a different Tab

 Thank you for your reply...

but it's still throwing the exception when i try to delete the tab area...

 

 

 

 

public void Refresh()
 {
  final VerticalFieldManager newTab = displayTab2();
  UiApplication.getUiApplication().invokeLater(new Runnable()
  {
    public void run()
    {
      if(tabArea != null && tabArea.getManager() == getMainManager())
      {        
         delete(tabArea); ////exception
      }
         tabArea = newTab;
         add(tabArea);
    }
  });
}

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Selecting a different Tab

Next time please quote the text of exception - it'll save the questions here.

 

Anyway, this should work no matter what:

 

Manager m;
if (tabArea != null && (m = tabArea.getManager()) != null) {
  m.delete(tabArea);
}
...

 

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 37
Registered: ‎10-15-2010
My Device: Not Specified

Re: Selecting a different Tab

tx ....but i m still getting the following exception....

could you tell me y?

 

Uncaught exception thrown - IllegalArgumentException

 

 

 public void Refresh()
 {
  final VerticalFieldManager newTab = displayTab2();
   UiApplication.getUiApplication().invokeLater(new Runnable()
   {
       public void run()
      {
          Manager m;
         if (tabArea != null && (m = tabArea.getManager()) != null)
        {
            m.delete(tabArea); //here its happens tabArea --> illegalArgument
           tabArea = newTab;
           m.add(tabArea);
        }
     }
  });
}

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Selecting a different Tab

Well,

people here are volunteers and cannot debug the code for you. When you get an exception, investigate more before posting. Debugger shows the actual classes of involved objects; you can check whether anything is null, look inside the objects at the private members, compare, analyze and think.

 

We are not at your keyboard watching over your shoulder - do your homework, read the documentation and think, think, think!

Only you can check what tabArea or m is, find its manager and, if necessary, its Manager's manager and what their Classes actually are. Do that, dig more, train yourself to use the debugger - you must have this skill to become successful at software development.

 

By the way, your code now is wrong - tabArea = newTab; and add(tabArea); (not m.add(tabArea)!) should happen outside (after) that if (tabArea != null...).

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 16,644
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Selecting a different Tab

sometimes it is best to step a bit back from the code and try to visualize what it does. maybe draw something on a sheet of paper, like the structure of managers you are building.

it also helps if you give your fields self-speaking names, with "m" you will not go far. always write code with the possibility in mind that somebody else may want to check/change/view it. this includes comments, but also a self-explaining code.

 

when you come back to your project after a few months to do some bugfixes or add some features you will be thankful for your efforts.

and, as a plus, it also helps with your current problem.

 

in university we spent 4 days analyzing, drawing UML etc, then one day implementing it.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter