-1
아래 코드에서 myReverseGeocode address = new myReverseGeocode (위도, 경도)를 호출합니다. , gpsData.append (address.temp); 항상 거의 immediatelly Thread
가 (즉, myReverseGeocode
의 생성자에서 시작)가 시작 된 후 요청 때문에 항상 null
로 temp
을 얻을 "널 (null)"myReverseGeocode가 시작되지 않습니다.
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";
else
temp = "in else";
}
catch (LocatorException lex)
{
}
}
};
reverseGeocode = new Thread(thread);
reverseGeocode.setPriority(Thread.MIN_PRIORITY);
reverseGeocode.start();
}
}
이 코드는 컴파일되지 않습니다. –
잘 코드가 컴파일 중입니다 ... 전체 코드가 아닌 부분 코드 만 붙여 넣었습니다 ... – Amar