我正在尝试从EditText获取文本,并将其作为该函数的两倍传递
这是我的代码:
private MapViewLite mapView;
EditText lat,longs;
Button search;
String getLang,getlong;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lat = findViewById(R.id.lat);
longs = findViewById(R.id.longs);
search = findViewById(R.id.search);
// Get a MapViewLite instance from the layout.
mapView = findViewById(R.id.map_view);
mapView.onCreate(savedInstanceState);
getLang = lat.getText().toString();
getlong = longs.getText().toString();
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
loadMapScene(getLang,getlong);
}
});
}
private void loadMapScene(String a,String b) {
// Load a scene from the SDK to render the map with a map style.
mapView.getMapScene().loadScene(MapStyle.NORMAL_DAY, new LoadSceneCallback() {
@Override
public void onLoadScene(@Nullable SceneError sceneError) {
if (sceneError == null) {
try {
double aa = new Double(getLang);
double bb = new Double(getlong);
mapView.getCamera().setTarget(new GeoCoordinates(aa, bb));
mapView.getCamera().setZoomLevel(14);
}catch (Exception e){
Log.e("Catch :", e.getMessage());
e.printStackTrace();
}
} else {
Log.e("ERROR ->>> ", "onLoadScene failed: " + sceneError.toString());
}
}
});
我单击按钮后,我得到的错误为:
W/System.err: java.lang.NumberFormatException: Invalid double: ""
如何修复此错误,请回复
最佳答案
你在打电话
getLang = lat.getText().toString();
getlong = longs.getText().toString();
来自
onCreate()
这些值未设置为yes,因此其文本为“”;
将它们移到
loadMapScene()
方法中