开发者

myReverseGeocode is not starting.

In below code when i call myReverseGeocode address = new myReverseGeocode(latitude, longitude); , gpsData.append(address.temp); always show "null"

public HelloBlackBerryScreen() {
        super( MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR );
        setTitle( "Get Address" );

        ButtonField buttonField_1 = new ButtonField( "Get GPS", ButtonField.CONSUME_CLICK | ButtonField.FIELD_RIGHT );
        add( buttonField_1 );
        buttonField_1.setChangeListener( new FieldChangeListener() {
            public void fieldChanged( Field arg0, int arg1 ) {
                Criteria c = new Criteria();                      

                try {
                    LocationProvider lp = LocationProvider.getInstance(c);
                    if( lp!=null )
                    {
                        lp.setLocationListener(new LocationListenerImpl(), 3, 1, 1);
                        myReverseGeocode address = new myReverseGeocode(latitude, longitude);

                        gpsData.append(address.temp);
                        myloc = gpsData.toString();
                    }



                } catch (LocationException le) {                        
                    ;
                }

myReverseGeocode.java


package mypackage;

import javax.microedition.location.AddressInfo;
import javax.microedition.location.Landmark;

import net.rim.device.api.lbs.Locator;
import net.rim.device.api.lbs.LocatorException;

public class myReverseGeocode {
    private Thread reverseGeocode;
    public AddressInfo addrInfo = null;
    String temp;

    public myReverseGeocode(final double lt, final double ln)
    {
         Runnable thread = new Runnable()
            {
                public void run()
                {

                    int latitude  = (int)(lt * 100000);
                    int longitude = (int)(ln * 100000);
                    try
                    {
                        Landmark[] results = Locator.reverseGeocode(latitude, longitude, Locator.ADDRESS );

                        if ( results != null && results.length > 0 )
                            temp = "inside if";
                  开发者_StackOverflow中文版      else
                            temp = "in else";
                    }
                    catch ( LocatorException lex )
                    {
                    }
                }
            };
        reverseGeocode = new Thread(thread);
        reverseGeocode.setPriority(Thread.MIN_PRIORITY);
        reverseGeocode.start();
    }

}


You always get temp as null because you ask for it almost immediatelly after the Thread (that is started in constructor of the myReverseGeocode) has been started. You need to redesign your myReverseGeocode to udate the UI of the screen after an actual temp value is got.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜