【发布时间】:2012-03-23 19:40:34
【问题描述】:
我正在尝试创建一个显示模拟位置的应用程序。但是,当我单击按钮显示位置时,我得到应用程序意外停止的异常。代码如下:
public class AndroidLBS extends Activity {
public static TextView latText;
public static TextView lngText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button gpsButton = (Button) findViewById(R.id.gpsButton);
gpsButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
LoadCoords();}
});
}
public void LoadCoords()
{
latText = (TextView) findViewById(R.id.latText);
lngText = (TextView) findViewById(R.id.lngText);
Intent in=new Intent("LOC_OBTAINED");
PendingIntent pi=PendingIntent.getBroadcast(this,0,in,0);
registerReceiver(new BroadcastReceiver(){
public void onReceive(Context arg0, Intent arg1)
{
Bundle bundle=arg1.getExtras();
Location loc=(Location)bundle.get(LocationManager.KEY_LOCATION_CHANGED);
Double lat=loc.getLatitude();
Double longitude=loc.getLongitude();
latText.setText(lat.toString());
lngText.setText(longitude.toString());
}
},new IntentFilter("LOC_OBTAINED"));
LocationManager myManager=LocationManager)getSystemService(Context.LOCATION_SERVICE);
myManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER,true);
Location loc=new Location(LocationManager.GPS_PROVIDER);
loc.setLatitude(12.9);
loc.setLongitude(72.9);
myManager.setTestProviderLocation(LocationManager.GPS_PROVIDER,loc);
myManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, pi);
}
}
谁能帮我解决这个问题?提前致谢!
【问题讨论】:
-
你能发布例外吗?
-
可能是 stackoverflow.com/questions/8298732/… 的骗子,但没有关于如何添加权限或日志/堆栈跟踪的信息,很难知道。考虑到这有多老了,如果关闭它就永远无法解决这一事实?