首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android GPS位置获取 为何总是不能运行?

2013-01-01 
Android GPS位置获取 为什么总是不能运行??!!!在网上找了各个版本的GPS定位,可是都不能运行!要么是Sorry,t

Android GPS位置获取 为什么总是不能运行??!!!
在网上找了各个版本的GPS定位,可是都不能运行!要么是Sorry,the application has stopped unexpectly.Please try agian.要么就是在DDMS send经纬度之后毫无反应……哭……
到底哪里出了问题?请各位大侠们指点!不胜感激!
下面是源码:
MainActivity.java


            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission>    
</manifest>

main.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
    <Button 
    android:id="@+id/locationButtonId"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@+string/绑定监听器"/>
</LinearLayout>

[解决办法]
引用:
the application has stopped unexpectly问题解决了,原来是manifest文件中的activity名写错了。。。


拿来别人代码借鉴很容易犯这个错误 
[解决办法]
因为你的模拟器不支持GSP功能,并且是获取上一次得到的location,而上一次根本就没有,所以location 总是为空的,我想如果在真机上应该可以的。
[解决办法]
在模拟器中,楼主应该要先在DDMS视图中发送经纬度,再绑定监听器(button.setOnClickListener(new ButtonListener())),然后才能获取经纬度值,不然返回的就是空值。。。。

热点排行