myReverseGeocode 未启动。
在下面的代码中,当我调用 myReverseGeocode address = new myReverseGeocode(latitude, longitude); 时, gpsData.append(address.temp);总是显示“空”
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();
}
}
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";
else
temp = "in else";
}
catch ( LocatorException lex )
{
}
}
};
reverseGeocode = new Thread(thread);
reverseGeocode.setPriority(Thread.MIN_PRIORITY);
reverseGeocode.start();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您总是将
temp
设为null
,因为您几乎在Thread
之后立即请求它(在myReverseGeocode< 的构造函数中启动) /code>) 已启动。您需要重新设计
myReverseGeocode
以在获取实际temp
值后更新屏幕的 UI。You always get
temp
asnull
because you ask for it almost immediatelly after theThread
(that is started in constructor of themyReverseGeocode
) has been started. You need to redesign yourmyReverseGeocode
to udate the UI of the screen after an actualtemp
value is got.