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
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Cannot use "this" in a static context

You are still showing the design rather than objective but this time it's closer.

 

Here is my take:

I don't see anything here that requires you to use static methods. From your description I can guess that you are stuck somewhere around steps 6-8. Now let's see:

 

 

  • itemAdded, itemUpdated, itemRemoved methods are not and cannot be static. So you have "this" there.
  • setfromcod method should not be static - you are trying to refresh a screen, after all, which is a specific object. If it is static, you have some design flaw there. So "this" should be implicitly passed to setfromcod.
  • The refresh method should most definitely know what is refreshes, so it should not be static. "this" is still available.

 

If you have any static methods called from those above, don't try to put non-static calls in those static methods. Alternatively, you might want to pass "this" to those static methods explicitly as a parameter.

----------------------------------------------------------
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: 172
Registered: ‎04-19-2010
My Device: Bold 9700

Re: Cannot use "this" in a static context

Hi,

 

this is my listenerclass

 

import javax.microedition.pim.PIMException;
import javax.microedition.pim.PIMItem;
import net.rim.blackberry.api.pdap.PIMListListener;

public class PIMListener implements PIMListListener {
	public PIMListener() {}

	public void itemAdded(PIMItem item) {
		GridScreen.setfromcod;
	}

	public void itemRemoved(PIMItem item) {
		GridScreen.setfromcod;
	}

	public void itemUpdated(PIMItem oldItem, PIMItem newItem) {
		GridScreen.setfromcod;
	}

}

 and this is the method in gridscreen

 

 

	static void setfromcod(){
		SelectedCalendarList = true;
                if(SelectedCalendarList) {
getevents();
}
}

 

 

WIthin eclipse, each is in a separate file.

 

setfromcod should be static, if i try to call it that way.(Eclipse is firing an error if not declared as static).

and selectedcalendarlist also. And getevents, etc...

 

 

cu
michael
--------------------------------------------------------------------------------------------------------------------------
please give kudos to thank everyone who helped you or put you in the right direction.
please mark the thread as solved, if you found your solution.
Developer
Posts: 16,637
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Cannot use "this" in a static context

use a global event if you want to communicate between applications.
----------------------------------------------------------
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
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Cannot use "this" in a static context

Oh, now I see your problem! You don't need PIMListener class. Your GridScreen should implement PIMListListener and have those itemAdded etc. methods implemented. Then setfromcod becomes a non-static call.

 

You add your screen as a listener in its onDisplay() (onUiEngineAttached() in later OS versions) and remove it as a listener in onUndisplay (or, again, onUiEngineAttached()). addListener(this) and removeListener(this), respectively.

----------------------------------------------------------
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: 172
Registered: ‎04-19-2010
My Device: Bold 9700

Re: Cannot use "this" in a static context

@simon and @arcadyz,

 

thanks for the information.

 

sorry: but what do you mean(both)?

 

cu
michael
--------------------------------------------------------------------------------------------------------------------------
please give kudos to thank everyone who helped you or put you in the right direction.
please mark the thread as solved, if you found your solution.
Developer
Posts: 16,637
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Cannot use "this" in a static context

arcadyz is on the right track i think. use http://download.oracle.com/javase/tutorial/java/IandI/usinginterface.html together with http://www.blackberry.com/developers/docs/6.0.0api/net/rim/blackberry/api/pdap/PIMListListener.html and your screen. or even easier said: 1. go to your screen. 2. let it implement PIMListListener 3. profit
----------------------------------------------------------
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
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Cannot use "this" in a static context

Your GridScreen class should start somewhat like this:

 

public class GridScreen extends MainScreen implements PIMListListener {

 

 

----------------------------------------------------------
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: 172
Registered: ‎04-19-2010
My Device: Bold 9700

Re: Cannot use "this" in a static context

oh,

 

I think I understand.

 

Thank you(both) very much, I hope you put me in the right direction.

 

I try it out and let you know if it worked.

 

thanks again.

cu
michael
--------------------------------------------------------------------------------------------------------------------------
please give kudos to thank everyone who helped you or put you in the right direction.
please mark the thread as solved, if you found your solution.
Developer
Posts: 172
Registered: ‎04-19-2010
My Device: Bold 9700

Re: Cannot use "this" in a static context

Hi,

 

sorry for the late answer.

 

It is working fine so far.

 

I let my screen implementing PIMListListener, so I haven't the trouble with the static context.

 

You put me in the right direction.

 

Thanks @simon and @arkadyz.

 

@simon I haven't used your articles, but I try to get them as fast as I can.

cu
michael
--------------------------------------------------------------------------------------------------------------------------
please give kudos to thank everyone who helped you or put you in the right direction.
please mark the thread as solved, if you found your solution.