致命异常:主要java.lang.NoClassDefFoundError:com.mtower.adha.ui.MapDetail

时间:2013-12-18 03:06:50

标签: java android google-maps mapactivity

我正在使用googlemaps v2,首先我收到错误“无法获取连接工厂客户端”Android MapActivity googlemaps : Couldn't get connection factory client。我尝试从一些教程中修复它,现在得到错误“FATAL EXCEPTION:main java.lang.NoClassDefFoundError”。

Logcat错误

12-18 09:48:40.670: V/SQLITE(330): Check DB on /data/data/com.mtower.adha/databases/mtowerdb.sqlite
12-18 09:48:40.790: I/coba(330): async start
12-18 09:48:41.470: D/dalvikvm(330): GC_FOR_MALLOC freed 2156 objects / 137792 bytes in 80ms
12-18 09:48:41.570: E/json error(330): Value <?xml of type java.lang.String cannot be converted to JSONArray
12-18 09:48:41.600: W/dalvikvm(330): Unable to resolve superclass of Lcom/mtower/adha/ui/Map; (1725)
12-18 09:48:41.610: W/dalvikvm(330): Link of class 'Lcom/mtower/adha/ui/Map;' failed
12-18 09:48:41.610: E/dalvikvm(330): Could not find class 'com.mtower.adha.ui.Map', referenced from method com.mtower.adha.ui.MTowerActivity.onMapClick
12-18 09:48:41.610: W/dalvikvm(330): VFY: unable to resolve const-class 1755 (Lcom/mtower/adha/ui/Map;) in Lcom/mtower/adha/ui/MTowerActivity;
12-18 09:48:41.610: D/dalvikvm(330): VFY: replacing opcode 0x1c at 0x0002
12-18 09:48:41.610: D/dalvikvm(330): VFY: dead code 0x0004-000a in Lcom/mtower/adha/ui/MTowerActivity;.onMapClick (Landroid/view/View;)V
12-18 09:48:43.290: W/dalvikvm(330): Unable to resolve superclass of Lcom/mtower/adha/ui/MapDetail; (1725)
12-18 09:48:43.290: W/dalvikvm(330): Link of class 'Lcom/mtower/adha/ui/MapDetail;' failed
12-18 09:48:43.290: E/dalvikvm(330): Could not find class 'com.mtower.adha.ui.MapDetail', referenced from method com.mtower.adha.ui.Tower.onItemClick
12-18 09:48:43.290: W/dalvikvm(330): VFY: unable to resolve const-class 1757 (Lcom/mtower/adha/ui/MapDetail;) in Lcom/mtower/adha/ui/Tower;
12-18 09:48:43.290: D/dalvikvm(330): VFY: replacing opcode 0x1c at 0x0010
12-18 09:48:43.290: D/dalvikvm(330): VFY: dead code 0x0012-001d in Lcom/mtower/adha/ui/Tower;.onItemClick (Landroid/widget/AdapterView;Landroid/view/View;IJ)V
12-18 09:48:43.310: V/SQLITE(330): Opening DB on /data/data/com.mtower.adha/databases/mtowerdb.sqlite
12-18 09:48:43.330: I/coba(330): Nama: BG3021
12-18 09:48:43.330: I/coba(330): Nama: BG3039
12-18 09:48:43.340: I/coba(330): Nama: BKG017
12-18 09:48:43.340: I/coba(330): Nama: BKG020
12-18 09:48:43.340: I/coba(330): Nama: BKG051
12-18 09:48:43.350: I/coba(330): Nama: BKG084
12-18 09:48:43.360: I/coba(330): Nama: BKG112
12-18 09:48:43.360: I/coba(330): Nama: BKG299
12-18 09:48:43.360: I/coba(330): Nama: BKG577
12-18 09:48:43.370: I/coba(330): Nama: PBR788
12-18 09:48:43.370: V/SQLITE(330): Closing DB
12-18 09:48:43.950: D/dalvikvm(330): GC_FOR_MALLOC freed 5194 objects / 277056 bytes in 82ms
12-18 09:48:45.060: D/dalvikvm(330): GC_FOR_MALLOC freed 5349 objects / 571416 bytes in 127ms
12-18 09:48:45.550: D/dalvikvm(330): GC_FOR_MALLOC freed 8518 objects / 411568 bytes in 139ms
12-18 09:48:45.831: D/AndroidRuntime(330): Shutting down VM
12-18 09:48:45.831: W/dalvikvm(330): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-18 09:48:45.840: E/AndroidRuntime(330): FATAL EXCEPTION: main
12-18 09:48:45.840: E/AndroidRuntime(330): java.lang.NoClassDefFoundError: com.mtower.adha.ui.MapDetail
12-18 09:48:45.840: E/AndroidRuntime(330):  at com.mtower.adha.ui.Tower.onItemClick(Tower.java:70)
12-18 09:48:45.840: E/AndroidRuntime(330):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
12-18 09:48:45.840: E/AndroidRuntime(330):  at android.widget.ListView.performItemClick(ListView.java:3382)
12-18 09:48:45.840: E/AndroidRuntime(330):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
12-18 09:48:45.840: E/AndroidRuntime(330):  at android.os.Handler.handleCallback(Handler.java:587)
12-18 09:48:45.840: E/AndroidRuntime(330):  at android.os.Handler.dispatchMessage(Handler.java:92)
12-18 09:48:45.840: E/AndroidRuntime(330):  at android.os.Looper.loop(Looper.java:123)
12-18 09:48:45.840: E/AndroidRuntime(330):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-18 09:48:45.840: E/AndroidRuntime(330):  at java.lang.reflect.Method.invokeNative(Native Method)
12-18 09:48:45.840: E/AndroidRuntime(330):  at java.lang.reflect.Method.invoke(Method.java:521)
12-18 09:48:45.840: E/AndroidRuntime(330):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-18 09:48:45.840: E/AndroidRuntime(330):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-18 09:48:45.840: E/AndroidRuntime(330):  at dalvik.system.NativeStart.main(Native Method)
12-18 09:48:46.970: D/dalvikvm(330): GC_FOR_MALLOC freed 7510 objects / 369912 bytes in 419ms
12-18 09:48:47.490: I/Process(330): Sending signal. PID: 330 SIG: 9

Map.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<greendroid.widget.ActionBar
    android:id="@+id/myActionBar"
    android:layout_width="fill_parent"
    android:layout_height="30dp"
    android:background="@drawable/action_bar_background" />

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:enabled="true" 
    class="com.google.android.gms.maps.SupportMapFragment" />


    <LinearLayout
        android:id="@+id/zoom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

</LinearLayout>

AndroidManifest

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

<uses-sdk android:minSdkVersion="8" />

<permission
    android:name="com.mtower.adha.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>

<uses-permission android:name="com.mtower.adha.permission.MAPS_RECEIVE"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CALL_PHONE" ></uses-permission>

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

<application
    android:icon="@drawable/bc1"
    android:label="@string/app_name"
    android:name=".mmMtowerApplication"
    android:theme="@style/Theme.coba" >
    <activity
        android:label="@string/app_name"
        android:name=".ui.MTowerOpening"
        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=".ui.MTowerActivity"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".ui.Underconstructions"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".ui.Tower"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".ui.TowerDetailInformation"
        android:screenOrientation="portrait"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".ui.About"
        android:screenOrientation="portrait"
        android:label="about aplikasi" >
    </activity>
    <activity
        android:name=".ui.MapRoute"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".ui.Map"
        android:screenOrientation="portrait" >
    </activity>
     <activity
        android:name=".ui.MapDetail"
        android:screenOrientation="portrait" >
    </activity>

     <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyAuuV6dsdfsdfsdsdtp8yA0spDaQcEjsmkiNhrcW3Q-Q"/>

</application>





</manifest>

map.java

package com.mtower.adha.ui;

import greendroid.widget.ActionBar;
import greendroid.widget.ActionBar.Type;

import java.util.List;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.mtower.adha.R;
import com.mtower.adha.db.TowerController;
import com.mtower.adha.models.TowerModel;
import com.mtower.adha.utilities.MapOverlay;


public class Map extends MapActivity {

private MapView mapView;
private ActionBar actionBar;
private MapController mapController;
private GeoPoint gpUser, p;
private SharedPreferences prefLocation;

private Context mContext;
String lat, lon, name, alamat;
@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.map);
    mContext = this;

    actionBar = (ActionBar) findViewById(R.id.myActionBar);
    actionBar.setTitle("Cellular Tower Maps");
    actionBar.setType(Type.Empty);
    actionBar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });
    actionBar.getHandler();


    initMap();
}

@SuppressWarnings("deprecation")
public void initMap() {
    mapView = (MapView) findViewById(R.id.map);
    View zoomView = mapView.getZoomControls();
    LinearLayout myzoom = (LinearLayout) findViewById(R.id.zoom);
    myzoom.addView(zoomView);
    mapView.setStreetView(false);
    mapView.setBuiltInZoomControls(true);
    mapView.displayZoomControls(true);
    // Untuk mengambil lokasi user saat ini
    prefLocation = mContext.getSharedPreferences("mkul", 0);
    double latUser = Double.parseDouble(prefLocation.getString("userLat",
            "0"));
    double lonUser = Double.parseDouble(prefLocation.getString("userLon",
            "0"));
    gpUser = new GeoPoint((int) (latUser * 1E6), (int) (lonUser * 1E6));

    mapController = mapView.getController();

    TowerController rc = new TowerController(mContext);
    List<TowerModel> lsRm = rc.getAll();

    for (int i = 0; i < lsRm.size(); i++) {
        TowerModel poi = lsRm.get(i);

        lat = poi.getLat();
        lon = poi.getLon();
        name = poi.getName();
        alamat = poi.getAddress();

        String coordinates[] = {lat, lon};

        double lati = Double.parseDouble(coordinates[0]);
        double longi = Double.parseDouble(coordinates[1]);

        p = new GeoPoint((int) (lati * 1E6), (int) (longi * 1E6));

        List<Overlay> mapOverlays = mapView.getOverlays();
        int draw = R.drawable.marker;
        Drawable drawable = this.getResources().getDrawable(draw);
        MapOverlay itemizedoverlay = new MapOverlay(drawable,mContext,poi);
        OverlayItem overlayitem = new OverlayItem(p, name, alamat);
        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);
    }
    mapController.animateTo(gpUser);
    mapController.setZoom(16); 
}

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

}

mapdetail.java

package com.mtower.adha.ui;

import greendroid.widget.ActionBar;
import greendroid.widget.ActionBar.Type;

import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.mtower.adha.R;
import com.mtower.adha.models.TowerModel;
import com.mtower.adha.utilities.MapOverlay;


public class MapDetail extends MapActivity {

private MapView mapView;
private ActionBar actionBar;
private MapController mapController;
private GeoPoint gpUser, p;
private Context mContext;

String lat, lon, name, alamat;
TowerModel rm;

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.map);
    mContext = this;

    actionBar = (ActionBar) findViewById(R.id.myActionBar);
    actionBar.setTitle("Cellular Tower Maps");
    actionBar.setType(Type.Empty);
    actionBar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });
    actionBar.getHandler();


    initMap();
}

@SuppressWarnings("deprecation")
public void initMap() {
    mapView = (MapView) findViewById(R.id.map);
    View zoomView = mapView.getZoomControls();
    LinearLayout myzoom = (LinearLayout) findViewById(R.id.zoom);
    myzoom.addView(zoomView);
    mapView.setStreetView(false);
    mapView.setBuiltInZoomControls(true);
    mapView.displayZoomControls(true);
    // Untuk mengambil lokasi user saat ini

    rm = (TowerModel) getIntent().getParcelableExtra("tower");
    double latUser = Double.parseDouble(rm.getLat());
    double lonUser = Double.parseDouble(rm.getLon());
    gpUser = new GeoPoint((int) (latUser * 1E6), (int) (lonUser * 1E6));

    mapController = mapView.getController();



        lat = rm.getLat();
        lon = rm.getLon();
        name = rm.getName();
        alamat = rm.getAddress();

        String coordinates[] = {lat, lon};

        double lati = Double.parseDouble(coordinates[0]);
        double longi = Double.parseDouble(coordinates[1]);

        p = new GeoPoint((int) (lati * 1E6), (int) (longi * 1E6));

        List<Overlay> mapOverlays = mapView.getOverlays();
        int draw = R.drawable.marker;
        Drawable drawable = this.getResources().getDrawable(draw);
        MapOverlay itemizedoverlay = new MapOverlay(drawable,mContext,rm);
        OverlayItem overlayitem = new OverlayItem(p, name, alamat);
        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);

    mapController.animateTo(gpUser);
    mapController.setZoom(16); 
}

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

 }

2 个答案:

答案 0 :(得分:1)

试试这个:

转到项目/属性/ Java构建路径/订单和导出 - 如果您使用它,请确保在Android Dependencies和支持库前面进行检查。标记所有复选框并单击“应用”并清除项目。

希望这有帮助。

答案 1 :(得分:0)

首先你应该安装Extras-&gt; Android SDK管理器中的Google Play服务。然后,如果您使用的是Eclipse,请将库项目导入工作区。点击文件&gt;导入,选择Android&gt;将现有的Android代码导入Workspace,并浏览到库项目的副本以导入它。我可以解决这个问题。

有关详细信息:https://developers.google.com/maps/documentation/android/start