运行时错误而启动的地图(Runtime errors while Launching the Map

2019-10-21 11:04发布

这里的行以前用于启动地图和它的工作fine.Later我发现谷歌doen't使用LocationClient再和他们使用GoogleAPIClient instead.So我改成了我的onCreate()Method..The 2评论。

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button send = (Button) findViewById(R.id.button2);

        if(initMap())
        {  
            //mLocationClient = new LocationClient(this,this,this);
            //mLocationClient.connect();
            mGoogleApiClient =new GoogleApiClient.Builder(MainActivity.this)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(MainActivity.this)
            .addOnConnectionFailedListener(MainActivity.this)
            .build();
        }
        else
        {
            Toast.makeText(this,"Map Not Available!",Toast.LENGTH_SHORT).show();
        }
    }

这是initMap方法

private boolean initMap(){
        if(mMap==null)
        {
            //making Reference to Map Object
            SupportMapFragment mapFrag = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map); 
            mMap=mapFrag.getMap();
        }
        return(mMap!=null);
    }

这是logcat的报告。

12-20 15:45:47.195: E/AndroidRuntime(1457): FATAL EXCEPTION: main
12-20 15:45:47.195: E/AndroidRuntime(1457): Process: com.example.mapsproject, PID: 1457
12-20 15:45:47.195: E/AndroidRuntime(1457): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/R$styleable;
12-20 15:45:47.195: E/AndroidRuntime(1457):     at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2158)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:297)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.app.Activity.setContentView(Activity.java:2144)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at com.example.mapsproject.MainActivity.onCreate(MainActivity.java:71)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.app.Activity.performCreate(Activity.java:5933)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.app.ActivityThread.access$800(ActivityThread.java:144)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.os.Handler.dispatchMessage(Handler.java:102)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.os.Looper.loop(Looper.java:135)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at android.app.ActivityThread.main(ActivityThread.java:5221)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at java.lang.reflect.Method.invoke(Native Method)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at java.lang.reflect.Method.invoke(Method.java:372)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
12-20 15:45:47.195: E/AndroidRuntime(1457): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.R$styleable" on path: DexPathList[[zip file "/data/app/com.example.mapsproject-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
12-20 15:45:47.195: E/AndroidRuntime(1457):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-20 15:45:47.195: E/AndroidRuntime(1457):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
12-20 15:45:47.195: E/AndroidRuntime(1457):     ... 25 more
12-20 15:45:47.195: E/AndroidRuntime(1457):     Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.R$styleable
12-20 15:45:47.195: E/AndroidRuntime(1457):         at java.lang.Class.classForName(Native Method)
12-20 15:45:47.195: E/AndroidRuntime(1457):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
12-20 15:45:47.195: E/AndroidRuntime(1457):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
12-20 15:45:47.195: E/AndroidRuntime(1457):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
12-20 15:45:47.195: E/AndroidRuntime(1457):         ... 26 more
12-20 15:45:47.195: E/AndroidRuntime(1457):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
12-20 15:45:51.501: I/Process(1457): Sending signal. PID: 1457 SIG: 9

Answer 1:

这里是你的活动是有正常的问题,但是Eclipse并没有包括在APK支持包......如果你看看在堆栈跟踪你的错误上面,你会发现你的问题的根源:

 Didn't find class "com.google.android.gms.R$styleable" on path: DexPathList[[zip file "/data/app/com.example.mapsproject-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

所以,你可以解开APK,其水下爆炸,你会看到不包括兼容包中的类。

为了解决这个问题

使用Eclipse

  • 用鼠标右键单击您的项目,
  • 性能
  • 构建路径
  • 去导出选项卡。
  • 确保“Android的私人图书馆”进行检查。
  • 干净,重建应该把你的轨道上......

使用过Android Studio

升级至Android Stuido 0.8.2之后,我有这个问题。 我尝试了很多的东西,包括

  • 清理项目
  • 清理项目(清洁的gradle)
  • 无效缓存和重新启动
  • 德晋级的活动名称在AndroidManifest.xml(.MyActivity)

没有工作,直到我重新导入整个项目。

File -> Close Project -> Import Project... -> Choose the same project -> OK

希望这会帮助,如果不是请评论如下。 :)



文章来源: Runtime errors while Launching the Map