我从一个 URL 获取 lat 和 lng。在我的编码中,它会像 if(lat==1.3005060 && lng== 103.8745850) ,它将打开下一个类 map.java。否则,无效的地图。
我最初将其声明为字符串以将其显示为文本视图。接下来我在 onClick 方法中将它声明为 float,以便它可以传递给谷歌地图。但是,会发生强制关闭错误。有人可以指导我吗?
LogCat 错误:
08-14 11:07:13.190: E/AndroidRuntime(457): FATAL EXCEPTION: main
08-14 11:07:13.190: E/AndroidRuntime(457): java.lang.IllegalStateException: Could not execute method of the activity
08-14 11:07:13.190: E/AndroidRuntime(457): at android.view.View$1.onClick(View.java:2185)
08-14 11:07:13.190: E/AndroidRuntime(457): at android.view.View.performClick(View.java:2585)
08-14 11:07:13.190: E/AndroidRuntime(457): at android.view.View$PerformClick.run(View.java:9299)
08-14 11:07:13.190: E/AndroidRuntime(457): at android.os.Handler.handleCallback(Handler.java:587)
08-14 11:07:13.190: E/AndroidRuntime(457): at android.os.Handler.dispatchMessage(Handler.java:92)
08-14 11:07:13.190: E/AndroidRuntime(457): at android.os.Looper.loop(Looper.java:130)
08-14 11:07:13.190: E/AndroidRuntime(457): at android.app.ActivityThread.main(ActivityThread.java:3691)
08-14 11:07:13.190: E/AndroidRuntime(457): at java.lang.reflect.Method.invokeNative(Native Method)
08-14 11:07:13.190: E/AndroidRuntime(457): at java.lang.reflect.Method.invoke(Method.java:507)
08-14 11:07:13.190: E/AndroidRuntime(457): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
08-14 11:07:13.190: E/AndroidRuntime(457): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
08-14 11:07:13.190: E/AndroidRuntime(457): at dalvik.system.NativeStart.main(Native Method)
08-14 11:07:13.190: E/AndroidRuntime(457): Caused by: java.lang.reflect.InvocationTargetException
08-14 11:07:13.190: E/AndroidRuntime(457): at java.lang.reflect.Method.invokeNative(Native Method)
08-14 11:07:13.190: E/AndroidRuntime(457): at java.lang.reflect.Method.invoke(Method.java:507)
08-14 11:07:13.190: E/AndroidRuntime(457): at android.view.View$1.onClick(View.java:2180)
08-14 11:07:13.190: E/AndroidRuntime(457): ... 11 more
08-14 11:07:13.190: E/AndroidRuntime(457): Caused by: java.lang.NumberFormatException: latitude
08-14 11:07:13.190: E/AndroidRuntime(457): at org.apache.harmony.luni.util.FloatingPointParser.initialParse(FloatingPointParser.java:114)
08-14 11:07:13.190: E/AndroidRuntime(457): at org.apache.harmony.luni.util.FloatingPointParser.parseFloat(FloatingPointParser.java:319)
08-14 11:07:13.190: E/AndroidRuntime(457): at java.lang.Float.parseFloat(Float.java:323)
08-14 11:07:13.190: E/AndroidRuntime(457): at com.example.fambond.SingleMenuItemActivity.onClick(SingleMenuItemActivity.java:75)
08-14 11:07:13.190: E/AndroidRuntime(457): ... 14 more
我的 singlemenu.java 代码的一部分
public void onClick(View v) {
//TODO Auto-generated method stub
float lat=Float.parseFloat(KEY_LATITUDE);
float lng =Float.parseFloat(KEY_LONGITUDE);
if(lat==1.3005060 && lng== 103.8745850){
Log.d("coords", "lat: " + KEY_LATITUDE + " long: " + KEY_LONGITUDE);
Intent intent = new Intent(SingleMenuItemActivity.this,map.class);
intent.putExtra("MAP",KEY_LATITUDE.toString());
intent.putExtra("MAP",KEY_LONGITUDE.toString());
startActivity(intent);
}
else
{
Toast.makeText(SingleMenuItemActivity.this, "Invalid MAP", Toast.LENGTH_LONG).show();
}
}