与谷歌地图开放新的意图有强制关闭错误 [英] Having force close error with open new intent for Google Map

查看:135
本文介绍了与谷歌地图开放新的意图有强制关闭错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的纬度和经度从一个网址。
在我的编码,
它会像,
如果(LAT == 1.3005060和放大器;&安培; LNG == 103.8745850)
它会打开了隔壁班的,map.java。
否则,无效的映射。

我最初声明为字符串,显示为文本视图。
接下来,我已经声明为浮动在onclick方法,
这样它可以传递给谷歌地图。
然而,
有强制关闭错误发生的历史。
有人可以指导我?

LogCat中错误:

  11月8日至14日:07:13.190:E / AndroidRuntime(457):致命异常:主要
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):java.lang.IllegalStateException:无法执行活动的方法
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在android.view.View $ 1.onClick(View.java:2185)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在android.view.View.performClick(View.java:2585)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在android.view.View $ PerformClick.run(View.java:9299)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在android.os.Handler.handleCallback(Handler.java:587)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在android.os.Handler.dispatchMessage(Handler.java:92)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在android.os.Looper.loop(Looper.java:130)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在android.app.ActivityThread.main(ActivityThread.java:3691)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在java.lang.reflect.Method.invokeNative(本机方法)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在java.lang.reflect.Method.invoke(Method.java:507)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:912)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在dalvik.system.NativeStart.main(本机方法)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):由:java.lang.reflect.InvocationTargetException
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在java.lang.reflect.Method.invokeNative(本机方法)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在java.lang.reflect.Method.invoke(Method.java:507)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在android.view.View $ 1.onClick(View.java:2180)
11月8日至一十四日:07:13.190:E / AndroidRuntime(457):11 ...更多
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):java.lang.NumberFormatException:产生的原因纬度
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在org.apache.harmony.luni.util.FloatingPointParser.initialParse(FloatingPointParser.java:114)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在org.apache.harmony.luni.util.FloatingPointParser.parseFloat(FloatingPointParser.java:319)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在java.lang.Float.parseFloat(Float.java:323)
一十一月8日至14日:07:13.190:E / AndroidRuntime(457):在com.example.fambond.SingleMenuItemActivity.onClick(SingleMenuItemActivity.java:75)
11月8日至一十四日:07:13.190:E / AndroidRuntime(457):14 ...更多

有关singlemenu.java我的code的一部分

 公共无效的onClick(视图v){
         // TODO自动生成方法存根
    浮经纬度= Float.parseFloat(KEY_LATITUDE);
    浮动液化天然气= Float.parseFloat(KEY_LONGITUDE);
    如果(LAT == 1.3005060和放大器;&安培; LNG == 103.8745850){
    Log.d(COORDS,纬度:+ KEY_LATITUDE +长:+ KEY_LONGITUDE);
    意向意图=新意图(SingleMenuItemActivity.this,map.class);
    intent.putExtra(MAP,KEY_LATITUDE.toString());
    intent.putExtra(MAP,KEY_LONGITUDE.toString());
    startActivity(意向);    }
    其他
    {
        Toast.makeText(SingleMenuItemActivity.this,无效图,Toast.LENGTH_LONG).show();
    }
}


解决方案

这个问题似乎是,你与比较花车​​== 标志。要测试平等的花车正确的方法是:

  IF((Math.abs(LAT-1.3005060)LT; EPSILON)及及(Math.abs(LNG-103.8745850)LT;小量)){
}

,其中小量就像0.00000001一个非常小的数,根据所希望的precision

请参阅What's错误使用==在Java中比较花车?和<一个href=\"http://stackoverflow.com/questions/2896013/manipulating-and-comparing-floating-points-in-java\">Manipulating和比较在Java 问题浮动点多。

I'm getting the lat and lng from one URL. In my coding, it will be like, if(lat==1.3005060 && lng== 103.8745850) , it will open up up the next class, map.java. else, invalid map.

I've initially declare it as string to display it as text view. Next I've declare it as float in the onClick method, so that it can pass to google map. However, there is force close error occuring. Can someone guide me?

LogCat Error:

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

part of my code for 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();
    }
}

解决方案

The problem seems to be that you are comparing floats with == sign. The correct way to test floats for 'equality' is:

if( (Math.abs(lat-1.3005060) < epsilon) && (Math.abs(lng-103.8745850) < epsilon) ){
}

where epsilon is a very small number like 0.00000001, depending on the desired precision.

See What's wrong with using == to compare floats in Java? and Manipulating and comparing floating points in java question for more.

这篇关于与谷歌地图开放新的意图有强制关闭错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆