"课程链接失败"在谷歌地图V2应用程序

时间:2015-02-12 13:17:49

标签: java android google-maps dalvik

我写了一个应用程序,它有一个Launcher活动和两个Map活动。

当我运行它时,一个Map活动就像一个梦,而另一个则与 java.lang.NoClassDefFoundError 崩溃。崩溃的人有一个"班级的链接失败"在我调用它之前发出警告

我已经通过 SO 的所有适用解决方案,似乎没有任何帮助。我有:

  • 检查并重新检查 Android清单

  • 完成了对 Java构建路径所做的所有建议。

  • 检查了活动的所有导入(崩溃),看看在清单

    android:minSdkVersion 之后没有实现

由于我的应用使用了 com.google.android.maps。* 类,因此我考虑使用

<uses-library android:name="com.google.android.maps" />
清单中的

元素,但产生了

Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY

根据 Commonsware,3月27日&#39; 14

&LT;您的清单中有一个元素。任

  • 不应该在那里,或

  • 您正在尝试在没有的设备上安装该应用 那个图书馆。 &GT;

我尝试将 maps.jar 手动插入我设备的文件夹中,但这并没有消除错误。

所以这是我的代码: Launcher Activity类(称为Selector.class):

package com.thenewboston.googlemaps;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Selector extends Activity implements View.OnClickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.select_activity);

        Button bMain = (Button)findViewById(R.id.button1);
        Button bOther = (Button)findViewById(R.id.button2);

        bMain.setOnClickListener(this);
        bOther.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()){
        case R.id.button1:
            Intent main_intent = new Intent(this,MainActivity.class);
            startActivity(main_intent);
            break;
        case R.id.button2:
            Intent other_intent = new Intent(this,OtherActivity.class);
            startActivity(other_intent);
            break;
        }

    }

}

My 2nd Map Activity名为OtherActivity.class(崩溃):

package com.thenewboston.googlemaps;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class OtherActivity extends MapActivity implements LocationListener{

    MapView  myMapView;
    long start,stop;
    int x,y;
    GeoPoint touchedPoint;
    Drawable d;
    List<Overlay> overlayList;
    LocationManager lm;
    String towers;

    @Override
    protected void onCreate(Bundle arg0) {
        // TODO Auto-generated method stub
        super.onCreate(arg0);
        setContentView(R.layout.otheractivity);
        myMapView = (MapView)findViewById(R.id.mvMain);
        myMapView.setBuiltInZoomControls(true);

        TouchControls tc = new TouchControls(); // set instance of touch controls
        @SuppressWarnings("unchecked")
        List<Overlay> overlayList = (List<Overlay>)myMapView.getOverlay();
        overlayList.add(tc);

        d = getResources().getDrawable(R.drawable.ic_launcher);

        // placing pinpoint at location
        lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        int lat = 0;
        int longi = 0;
        GeoPoint ourLocation = new GeoPoint(lat,longi); 
        OverlayItem overlayItem = new OverlayItem(ourLocation,"What's up?","2nd string");
        CustomPinpoints custom = new CustomPinpoints(d,OtherActivity.this);
        custom.insertPinpoint(overlayItem);
        overlayList.add(custom);
     }

    public class TouchControls extends Overlay{

            // Point p;
            AlertDialog alert;
            @Override
            public boolean onTouchEvent(MotionEvent arg0,
                    com.google.android.maps.MapView arg1) {
                // TODO Auto-generated method stub

                if (arg0.getAction() == MotionEvent.ACTION_DOWN){
                    start = arg0.getEventTime();
                    x = (int)arg0.getX();
                    y = (int)arg0.getY();
                // p = new Point(x,y);
                    touchedPoint = myMapView.getProjection().fromPixels(x,y);
                }
                if (arg0.getAction() == MotionEvent.ACTION_UP){
                    stop = arg0.getEventTime();
                }
                if (stop - start > 1500){
                    alert = new AlertDialog.Builder(OtherActivity.this).create();
                    alert.setTitle("Pick an option");
                    alert.setMessage("I told you to pick an option");
                    int whichButton = 0;
                    alert.setButton(whichButton, "place a pinpoint",new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub
                            OverlayItem overlayItem = new OverlayItem(touchedPoint,"What's up?","2nd string");
                            CustomPinpoints custom = new CustomPinpoints(d,OtherActivity.this);
                            custom.insertPinpoint(overlayItem);
                            overlayList.add(custom);
                        }
                    } );
                    int whichButton2 = 0;
                    alert.setButton(whichButton2 ,"get address",new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub
                            Geocoder geocoder = new Geocoder(getBaseContext(),Locale.getDefault());
                            try {
                                List<Address> address = geocoder.getFromLocation(touchedPoint.getLatitudeE6()/1E6, touchedPoint.getLongitudeE6()/1E6, 1);
                                String display = "";
                                if (address.size() > 0){
                                    for(int i = 0; i < address.get(0).getMaxAddressLineIndex(); i++){
                                        display += address.get(0).getAddressLine(i) + "\n";
                                    }
                                Toast t = Toast.makeText(getBaseContext(), display, Toast.LENGTH_LONG);
                                t.show();
                                }

                            } catch (IOException e ){
                                e.printStackTrace();
                            } finally {

                            }

                        }
                    } );
                    int whichButton3 = 0;
                    alert.setButton(whichButton3 ,"Toggle View",new DialogInterface.OnClickListener() {

                        @SuppressWarnings("deprecation")
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub
                            if (myMapView.isSatellite()){
                                myMapView.setSatellite(false);
                                myMapView.setStreetView(true);
                            } else {
                                myMapView.setStreetView(false);
                                myMapView.setSatellite(true);
                            }
                        }
                    } );

                    alert.show();
                 } //if 3

        return false;
        } 
    } // onTouchEvent

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onLocationChanged(Location arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderDisabled(String arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }
}

The Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.thenewboston.googlemaps"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
"
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >


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

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

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".OtherActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".CustomPinpoints"
            android:label="@string/app_name" >
        </activity>

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="whatever" />
    </application>

我的LogCat:

02-12 12:43:02.930: W/dalvikvm(14102): Unable to resolve superclass of Lcom/thenewboston/googlemaps/OtherActivity; (4650)
02-12 12:43:02.930: W/dalvikvm(14102): Link of class 'Lcom/thenewboston/googlemaps/OtherActivity;' failed
02-12 12:43:02.930: E/dalvikvm(14102): Could not find class 'com.thenewboston.googlemaps.OtherActivity', referenced from method com.thenewboston.googlemaps.Selector.onClick
02-12 12:43:02.930: W/dalvikvm(14102): VFY: unable to resolve const-class 4662 (Lcom/thenewboston/googlemaps/OtherActivity;) in Lcom/thenewboston/googlemaps/Selector;


02-12 12:44:10.200: D/AndroidRuntime(14102): Shutting down VM
02-12 12:44:10.200: W/dalvikvm(14102): threadid=1: thread exiting with uncaught exception (group=0x415e9ba8)
02-12 12:44:10.210: E/AndroidRuntime(14102): FATAL EXCEPTION: main
02-12 12:44:10.210: E/AndroidRuntime(14102): Process: com.thenewboston.googlemaps, PID: 14102
02-12 12:44:10.210: E/AndroidRuntime(14102): java.lang.NoClassDefFoundError: com.thenewboston.googlemaps.OtherActivity
02-12 12:44:10.210: E/AndroidRuntime(14102):    at com.thenewboston.googlemaps.Selector.onClick(Selector.java:35)
02-12 12:44:10.210: E/AndroidRuntime(14102):    at android.view.View.performClick(View.java:4438)
02-12 12:44:10.210: E/AndroidRuntime(14102):    at android.view.View$PerformClick.run(View.java:18422)
02-12 12:44:10.210: E/AndroidRuntime(14102):    at android.os.Handler.handleCallback(Handler.java:733)
02-12 12:44:10.210: E/AndroidRuntime(14102):    at android.os.Handler.dispatchMessage(Handler.java:95)
02-12 12:44:10.210: E/AndroidRuntime(14102):    at android.os.Looper.loop(Looper.java:136)
02-12 12:44:10.210: E/AndroidRuntime(14102):    at android.app.ActivityThread.main(ActivityThread.java:5017)
02-12 12:44:10.210: E/AndroidRuntime(14102):    at java.lang.reflect.Method.invokeNative(Native Method)
02-12 12:44:10.210: E/AndroidRuntime(14102):    at java.lang.reflect.Method.invoke(Method.java:515)
02-12 12:44:10.210: E/AndroidRuntime(14102):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:813)
02-12 12:44:10.210: E/AndroidRuntime(14102):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
02-12 12:44:10.210: E/AndroidRuntime(14102):    at dalvik.system.NativeStart.main(Native Method)

我的应用 Project Explorer enter image description here

有关该怎么做的任何想法?

1 个答案:

答案 0 :(得分:-1)

我想在为你的地图创建api密钥时,你没有提到这两个活动的包名,但只提到了第一个..