为什么当我的应用按位置获取地址时显示错误?

时间:2014-03-25 03:38:04

标签: android android-maps

我的代码:

GeoPoint p;
        if (location != null) {
            String country = "";
            if (isOnline()) {
                Geocoder geocoder = new Geocoder(getBaseContext(),
                        Locale.getDefault());
                p = new GeoPoint((int) (location.getLatitude() * 1E6),
                        (int) (location.getLongitude() * 1E6));
                List<Address> add = null;
                try {
                    add = geocoder.getFromLocation(p.getLatitudeE6() / 1E6,
                            p.getLongitudeE6() / 1E6, 1);
                } catch (Exception ex) {
                }
                addressjian = "";
                if (add != null && add.size() > 0) {
                    // Get address
                    String post = "";
                    for (int i = 0; i <= add.get(0)
                            .getMaxAddressLineIndex(); i++) {
                        country = add.get(0).getCountryName();
                        post = add.get(0).getPostalCode();
                        if (!add.get(0).getAddressLine(i).equals(country)) {
                            if (addressjian != null
                                    && !addressjian.equals("")) {
                                addressjian = addressjian + ", ";
                            }
                            addressjian += add.get(0).getAddressLine(i);
                        }
                    }
                    if (post != null && addressjian.contains(post)) {
                        addressjian = addressjian.replace(post, "");
                    }
                }
            }
            if (addressjian != null) {
                MainActivity.this.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        txtAddress.setText(addressjian);
                    }
                });
            }
        }

Manisfest

<uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.front"
        android:required="false" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
         <uses-library android:name="com.google.android.maps" />

        <activity
            android:name="com.share789.daitran.compasspro.MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.share789.daitran.compasspro.E028"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar" >
        </activity>

    </application>

例外:

 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.share789.daitran.compasspro/com.share789.daitran.compasspro.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.share789.daitran.compasspro.MainActivity" on path: /system/framework/com.google.android.maps.jar:/data/app/com.share789.daitran.compasspro-1.apk
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2219)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
    at android.app.ActivityThread.access$700(ActivityThread.java:159)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5419)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.share789.daitran.compasspro.MainActivity" on path: /system/framework/com.google.android.maps.jar:/data/app/com.share789.daitran.compasspro-1.apk
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:64)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
    ... 11 more

为什么按位置获取地址时会显示错误?

0 个答案:

没有答案