运行程序

时间:2016-07-21 06:41:20

标签: java android firebase

我不知道为什么每当我尝试运行我的地图应用程序时都会出现以下错误。 logcat如下

07-21 12:03:55.427 21046-21046/com.dutt.rishabh.locator E/AndroidRuntime:    FATAL EXCEPTION: main
Process: com.dutt.rishabh.locator, PID: 21046
java.lang.RuntimeException: Unable to get provider   com.google.firebase.provider.FirebaseInitProvider:   java.lang.ClassNotFoundException: Didn't find class   "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip  file "/data/app/com.dutt.rishabh.locator-2.apk"],nativeLibraryDirectories= [/data/app-lib/com.dutt.rishabh.locator-2, /vendor/lib, /system/lib]]
 at   android.app.ActivityThread.installProvider(ActivityThread.java:5064)
 at android.app.ActivityThread.installContentProviders(ActivityThread.java:4635)
 at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4575)
 at android.app.ActivityThread.access$1600(ActivityThread.java:151)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1414)
 at android.os.Handler.dispatchMessage(Handler.java:110)
 at android.os.Looper.loop(Looper.java:193)
 at android.app.ActivityThread.main(ActivityThread.java:5345)
 at java.lang.reflect.Method.invokeNative(Native Method)
 at java.lang.reflect.Method.invoke(Method.java:515)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
 at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.dutt.rishabh.locator-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.dutt.rishabh.locator-2, /vendor/lib, /system/lib]]
 at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
 at android.app.ActivityThread.installProvider(ActivityThread.java:5049)
 at android.app.ActivityThread.installContentProviders(ActivityThread.java:4635) 
 at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4575) 
 at android.app.ActivityThread.access$1600(ActivityThread.java:151) 
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1414) 
 at android.os.Handler.dispatchMessage(Handler.java:110) 
 at android.os.Looper.loop(Looper.java:193) 
 at android.app.ActivityThread.main(ActivityThread.java:5345) 
 at java.lang.reflect.Method.invokeNative(Native Method) 
 at java.lang.reflect.Method.invoke(Method.java:515) 
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828) 
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
 at dalvik.system.NativeStart.main(Native Method) 

源代码

package com.dutt.rishabh.locator;

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

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }


    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}

gradle构建文件

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"
    defaultConfig {
        applicationId "com.dutt.rishabh.locator"
        minSdkVersion 15
        targetSdkVersion 24
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner   "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.google.android.gms:play-services:9.2.0'
    testCompile 'junit:junit:4.12'
}

这是我的申请,但它总是给出上面提到的错误。请提供帮助! 上述问题已解决但现在出现以下错误。

07-21 12:32:20.223 26903-26903/com.dutt.rishabh.locator E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dutt.rishabh.locator, PID: 26903
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dutt.rishabh.locator/com.dutt.rishabh.locator.MapsActivity}: android.view.InflateException: Binary XML file line #4: Error inflating class fragment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441)
    at android.app.ActivityThread.access$900(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
    at android.os.Handler.dispatchMessage(Handler.java:110)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:5345)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #4: Error inflating class fragment
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:341)
    at android.app.Activity.setContentView(Activity.java:1948)
    at com.dutt.rishabh.locator.MapsActivity.onCreate(MapsActivity.java:20)
    at android.app.Activity.performCreate(Activity.java:5343)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441) 
    at android.app.ActivityThread.access$900(ActivityThread.java:151) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
    at android.os.Handler.dispatchMessage(Handler.java:110) 
    at android.os.Looper.loop(Looper.java:193) 
    at android.app.ActivityThread.main(ActivityThread.java:5345) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
    at dalvik.system.NativeStart.main(Native Method) 
 Caused by: java.lang.NullPointerException: name == null
    at java.lang.VMClassLoader.findLoadedClass(Native Method)
    at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:350)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:487)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    at android.support.v4.app.Fragment.isSupportFragmentClass(Fragment.java:464)
    at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2373)
    at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
    at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:374)
    at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:341) 
    at android.app.Activity.setContentView(Activity.java:1948) 
    at com.dutt.rishabh.locator.MapsActivity.onCreate(MapsActivity.java:20) 
    at android.app.Activity.performCreate(Activity.java:5343) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441) 
    at android.app.ActivityThread.access$900(ActivityThread.java:151) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
    at android.os.Handler.dispatchMessage(Handler.java:110) 
    at android.os.Looper.loop(Looper.java:193) 
    at android.app.ActivityThread.main(ActivityThread.java:5345) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
    at dalvik.system.NativeStart.main(Native Method) 

XML文件是

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.dutt.rishabh.locator.MapsActivity" />
</LinearLayout> 

请在这种情况下提供帮助。

2 个答案:

答案 0 :(得分:6)

不要包含整个游戏服务库,但要使用你需要的那个,我想更换一行:

compile 'com.google.android.gms:play-services:9.2.0'

使用:

compile 'com.google.android.gms:play-services-maps:9.2.0'

应解决您的问题

答案 1 :(得分:0)

作为在Android应用中启用Google API或Firebase服务的一部分,您可能需要将google-services插件添加到 root build.gradle 文件中:

dependencies {
    classpath 'com.google.gms:google-services:3.0.0'
    // ...
}

然后在app / build.gradle底部添加:

apply plugin: 'com.google.gms.google-services'

The Google Services Gradle Plugin

了解详情