2016-04-20 24 views
0

說實話,我不知道是什麼導致了錯誤,我第一次使用它們。 你能幫我解決這個問題嗎? 我只是試圖啓動谷歌地圖API進入fragmentActivity。 這是logcat的使用谷歌地圖API和碎片活性的錯誤

04-20 19:35:38.008: E/AndroidRuntime(3484): FATAL EXCEPTION: main 
04-20 19:35:38.008: E/AndroidRuntime(3484): Process: com.mom, PID: 3484 
04-20 19:35:38.008: E/AndroidRuntime(3484): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/mom/Map_activity; 
04-20 19:35:38.008: E/AndroidRuntime(3484):  at com.mom.MainActivity$2.onClick(MainActivity.java:88) 
04-20 19:35:38.008: E/AndroidRuntime(3484):  at android.view.View.performClick(View.java:4856) 
04-20 19:35:38.008: E/AndroidRuntime(3484):  at android.view.View$PerformClick.run(View.java:19956) 
04-20 19:35:38.008: E/AndroidRuntime(3484):  at android.os.Handler.handleCallback(Handler.java:739) 
04-20 19:35:38.008: E/AndroidRuntime(3484):  at android.os.Handler.dispatchMessage(Handler.java:95) 
04-20 19:35:38.008: E/AndroidRuntime(3484):  at android.os.Looper.loop(Looper.java:211) 
04-20 19:35:38.008: E/AndroidRuntime(3484):  at android.app.ActivityThread.main(ActivityThread.java:5389) 
04-20 19:35:38.008: E/AndroidRuntime(3484):  at java.lang.reflect.Method.invoke(Native Method) 
04-20 19:35:38.008: E/AndroidRuntime(3484):  at java.lang.reflect.Method.invoke(Method.java:372) 
04-20 19:35:38.008: E/AndroidRuntime(3484):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020) 
04-20 19:35:38.008: E/AndroidRuntime(3484):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815) 
04-20 19:35:38.008: E/AndroidRuntime(3484): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mom.Map_activity" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.mom-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 
04-20 19:35:38.008: E/AndroidRuntime(3484):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 
04-20 19:35:38.008: E/AndroidRuntime(3484):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
04-20 19:35:38.008: E/AndroidRuntime(3484):  at java.lang.ClassLoader.loadClass(ClassLoader.java:469) 
04-20 19:35:38.008: E/AndroidRuntime(3484):  ... 11 more 
04-20 19:35:38.008: E/AndroidRuntime(3484):  Suppressed: java.lang.NoClassDefFoundError: com.mom.Map_activity 
04-20 19:35:38.008: E/AndroidRuntime(3484):   at dalvik.system.DexFile.defineClassNative(Native Method) 
04-20 19:35:38.008: E/AndroidRuntime(3484):   at dalvik.system.DexFile.defineClass(DexFile.java:226) 
04-20 19:35:38.008: E/AndroidRuntime(3484):   at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219) 
04-20 19:35:38.008: E/AndroidRuntime(3484):   at dalvik.system.DexPathList.findClass(DexPathList.java:321) 
04-20 19:35:38.008: E/AndroidRuntime(3484):   at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54) 
04-20 19:35:38.008: E/AndroidRuntime(3484):   ... 13 more 
04-20 19:35:38.008: E/AndroidRuntime(3484):  Suppressed: java.lang.ClassNotFoundException: com.mom.Map_activity 
04-20 19:35:38.008: E/AndroidRuntime(3484):   at java.lang.Class.classForName(Native Method) 
04-20 19:35:38.008: E/AndroidRuntime(3484):   at java.lang.BootClassLoader.findClass(ClassLoader.java:781) 
04-20 19:35:38.008: E/AndroidRuntime(3484):   at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) 
04-20 19:35:38.008: E/AndroidRuntime(3484):   at java.lang.ClassLoader.loadClass(ClassLoader.java:504) 
04-20 19:35:38.008: E/AndroidRuntime(3484):   ... 12 more 
04-20 19:35:38.008: E/AndroidRuntime(3484):  Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 

,這是類

import android.annotation.SuppressLint; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 

public class Map_activity extends FragmentActivity { 

    public static android.support.v4.app.FragmentManager fragmentManager; 

    @SuppressLint("NewApi") 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.location_fragment); 

     fragmentManager = getSupportFragmentManager(); 
    } 

} 

import android.annotation.SuppressLint; 
import android.app.Fragment; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.MapView; 
import com.google.android.gms.maps.MapsInitializer; 
import com.google.android.gms.maps.model.BitmapDescriptorFactory; 
import com.google.android.gms.maps.model.CameraPosition; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 

@SuppressLint("NewApi") 
public class LocationFragment extends Fragment { 

    MapView mMapView; 
    private GoogleMap googleMap; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     // inflat and return the layout 
     View v = inflater.inflate(R.layout.location_fragment, container, 
       false); 
     mMapView = (MapView) v.findViewById(R.id.mapView); 
     mMapView.onCreate(savedInstanceState); 

     mMapView.onResume();// needed to get the map to display immediately 

     try { 
      MapsInitializer.initialize(getActivity().getApplicationContext()); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

     googleMap = mMapView.getMap(); 
     // latitude and longitude 
     double latitude = 17.385044; 
     double longitude = 78.486671; 

     // create marker 
     MarkerOptions marker = new MarkerOptions().position(
       new LatLng(latitude, longitude)).title("Hello Maps"); 

     // Changing marker icon 
     marker.icon(BitmapDescriptorFactory 
       .defaultMarker(BitmapDescriptorFactory.HUE_ROSE)); 

     // adding marker 
     googleMap.addMarker(marker); 
     CameraPosition cameraPosition = new CameraPosition.Builder() 
       .target(new LatLng(17.385044, 78.486671)).zoom(12).build(); 
     googleMap.animateCamera(CameraUpdateFactory 
       .newCameraPosition(cameraPosition)); 

     // Perform any camera updates here 
     return v; 
    } 

    @Override 
    public void onResume() { 
     super.onResume(); 
     mMapView.onResume(); 
    } 

    @Override 
    public void onPause() { 
     super.onPause(); 
     mMapView.onPause(); 
    } 

    @Override 
    public void onDestroy() { 
     super.onDestroy(); 
     mMapView.onDestroy(); 
    } 

    @Override 
    public void onLowMemory() { 
     super.onLowMemory(); 
     mMapView.onLowMemory(); 
    } 
} 

,這是明顯的

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

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

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

    <permission 
     android:name="com.arshad.map.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 

    <!-- Permission to receive Google Maps --> 
    <uses-permission android:name="com.arshad.map.permission.MAPS_RECEIVE" /> 

    <!-- Maps API needs OpenGL ES 2.0. --> 
    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > 
     <activity 
      android:name=".Splash" 
      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/title_activity_main" > 
     </activity> 
     <activity 
      android:name=".Add" 
      android:label="@string/title_activity_add" 
      android:windowSoftInputMode="adjustResize|stateVisible" > 
     </activity> 

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

     <activity 
      android:name=".Map_activity" 
      android:label="@string/title_activity_map" > 
     </activity> 

     <uses-library 
      android:name="com.google.android.maps" 
      android:required="true" /> 
    </application> 

</manifest> 
+0

您確定此清單中的此行是正確的嗎? package =「com.mom」。通常它看起來像com.companyname.myappname – noogui

+0

是的,我確定。多數民衆贊成我是如何命名包 –

回答

0

我有一個類似的問題和我通過將Google Play服務庫添加到我的項目中來修復它。將以下依賴項添加到您的Gradle文件中:compile 'com.google.android.gms:play-services:8.4.0'

+0

我已添加谷歌播放服務庫。 –

+0

我正在使用eclipse。日蝕中存在gradle。 如果是的話我在哪裏可以找到它。 –

+0

如果您在ADT中使用Eclipse,請查看將Google Play服務庫添加到項目的正確方法https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project(選擇Eclipse with ADT) –