我正在构建一个总线跟踪Android应用程序。用户通过edittext输入日志和lat,并将坐标传递给下一个活动。但是,当我尝试获取传递的数据并将其转换为double时,我得到一个空字符串错误。
strack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
currselectedBus=busListArray.getSelectedItem().toString();
new tracklat().execute(currselectedBus);
new tracklong().execute(currselectedBus);
res.setText("Tracking...");
Intent intent = new Intent(getApplicationContext(),
MapsActivity.class);
Bundle extras = new Bundle();
extras.putString("bus", currselectedBus.toString());
extras.putString("lat", vtxtValidation.getText().toString());
extras.putString("log", vtxtValidation2.getText().toString());
intent.putExtras(extras);
startActivity(intent);
}
});
然后我的代码获取字符串
public void onMapReady(GoogleMap googleMap) {
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String name=extras.getString("bus");
String lat = extras.getString("lat");
String log = extras.getString("log");
double lt = Double.parseDouble(lat);
double lg = Double.parseDouble(log);
mMap = googleMap;
LatLng loc = new LatLng(lt, lg);
mMap.addMarker(new MarkerOptions().position(loc).title(name));
mMap.moveCamera(CameraUpdateFactory.newLatLng(loc));
}
然后我收到以下错误
05-09 11:54:12.471 31709-31709/tosan.example.tosan.buslocation
E/AndroidRuntime: FATAL EXCEPTION: main
Process: tosan.example.tosan.buslocation, PID: 31709
java.lang.NumberFormatException: empty String
at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1071)
at java.lang.Double.parseDouble(Double.java:547)
at
tosan.example.tosan.buslocation.MapsActivity.onMapReady(MapsActivity.java:50)
at com.google.android.gms.maps.zzak.zza(Unknown Source)
at com.google.android.gms.maps.internal.zzaq.dispatchTransaction(Unknown
Source)
at com.google.android.gms.internal.maps.zzb.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:507)
at fh.b(:com.google.android.gms.dynamite_dynamitemodulesb@12529021@12.5.29 (040400-192802242):20)
at
com.google.android.gms.maps.internal.bg.a(:com.google.android.gms.dynamite_dyna
mitemodulesb@12529021@12.5.29 (040400-192802242):5)``
at
com.google.maps.api.android.lib6.impl.be.run(:com.google.android.gms.dynamite_d
ynamitemodulesb@12529021@12.5.29 (040400-192802242):5)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
05-09 11:54:14.449 31709-31958/tosan.example.tosan.buslocation W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
05-09 11:54:14.469 31709-31958/tosan.example.tosan.buslocation I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4
05-09 11:54:14.470 31709-31958/tosan.example.tosan.buslocation I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 4
05-09 11:54:14.493 31709-31958/tosan.example.tosan.buslocation W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/0000002b/n/arm64-v8a
05-09 11:54:15.663 31709-31930/tosan.example.tosan.buslocation I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
05-09 11:54:15.666 31709-31930/tosan.example.tosan.buslocation I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
05-09 11:54:16.546 31709-31718/tosan.example.tosan.buslocation I/art: Do partial code cache collection, code=18KB, data=30KB
05-09 11:54:16.548 31709-31718/tosan.example.tosan.buslocation I/art: After code cache collection, code=18KB, data=30KB
05-09 11:54:16.548 31709-31718/tosan.example.tosan.buslocation I/art: Increasing code cache capacity to 128KB