当前位置: 首页 > 知识库问答 >
问题:

Google Maps Android API v2-简单地图应用程序崩溃

阳俊德
2023-03-14

我是android开发的新手:)

我正在尝试创建一个简单的应用程序:一个带有地图的activity。我把我的HTC1X连接到电脑上,当我试图运行应用程序(通过intellij IDEA)时,它崩溃了。

我已经在网上(和stackoverflow)寻找线索,但没有找到任何线索。例如:
 -Google Maps v2-error
 -Google Map-RuntimeException-error Firting class Fragment

你能告诉我为什么吗??

谢谢,

奥马尔



技术详细信息:

HTC 1x runs android 4.1.1
Project External libraries:
 - Android 4.0 Google API's
 - Android-Support-V4.jar
 - google-play-services.jar



主要活动.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" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.SupportMapFragment"/>
</LinearLayout>



主要活动.java

package com.example.mapTest;

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

public class MainActivity extends FragmentActivity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainActivity);
    }
}



manifest.xml

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

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

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

    <permission
            android:name="com.example.mapTest.permission.MAPS_RECEIVE"
            android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.mapTest.permission.MAPS_RECEIVE"/>

    <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="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"/>

    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">

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

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



例外情况:

03-19 00:09:30.325: ERROR/NotificationService(434): Ignoring notification with icon==0: Notification(pri=0 contentView=null vibrate=null sound=nullnull defaults=0x0 flags=0x62 kind=[null])
03-19 00:09:41.430: ERROR/MediaScannerService(13421): Exception scanning file
        android.os.DeadObjectException
        at android.os.BinderProxy.transact(Native Method)
        at android.media.IMediaScannerListener$Stub$Proxy.scanCompleted(IMediaScannerListener.java:100)
        at com.android.providers.media.MediaScannerService$ServiceHandler.handleMessage(MediaScannerService.java:1007)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:155)
        at com.android.providers.media.MediaScannerService.run(MediaScannerService.java:713)
        at java.lang.Thread.run(Thread.java:864)
03-19 00:09:48.655: ERROR/ExternalAccountType(31657): Unsupported attribute readOnly
03-19 00:09:48.900: ERROR/ExternalAccountType(31657): Unsupported attribute readOnly
03-19 00:09:51.965: ERROR/EmbeddedLogger(434): App crashed! Process: com.example.mapTest
03-19 00:09:51.965: ERROR/EmbeddedLogger(434): App crashed! Package: com.example.mapTest v1 (1.0)
03-19 00:09:51.965: ERROR/EmbeddedLogger(434): Application Label: mapTest
03-19 00:09:51.965: ERROR/AndroidRuntime(22403): FATAL EXCEPTION: main
        java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
        at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
        at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
        at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:365)
        at android.app.Activity.setContentView(Activity.java:1912)
        at com.example.mapTest.MainActivity.onCreate(MainActivity.java:13)
        at android.app.Activity.performCreate(Activity.java:5066)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
        at android.app.ActivityThread.access$600(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:155)
        at android.app.ActivityThread.main(ActivityThread.java:5485)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
        at dalvik.system.NativeStart.main(Native Method)
03-19 00:09:53.785: ERROR/MediaScannerService(13421): Exception scanning file
        android.os.DeadObjectException
        at android.os.BinderProxy.transact(Native Method)
        at android.media.IMediaScannerListener$Stub$Proxy.scanCompleted(IMediaScannerListener.java:100)
        at com.android.providers.media.MediaScannerService$ServiceHandler.handleMessage(MediaScannerService.java:1007)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:155)
        at com.android.providers.media.MediaScannerService.run(MediaScannerService.java:713)
        at java.lang.Thread.run(Thread.java:864)
03-19 00:09:54.365: ERROR/NotificationService(434): Ignoring notification with icon==0: Notification(pri=0 contentView=null vibrate=null sound=nullnull defaults=0x0 flags=0x62 kind=[null])
03-19 00:10:03.075: ERROR/ExternalAccountType(31657): Unsupported attribute readOnly
03-19 00:10:03.380: ERROR/NotificationService(434): Ignoring notification with icon==0: Notification(pri=0 contentView=null vibrate=null sound=nullnull defaults=0x0 flags=0x62 kind=[null])
03-19 00:10:03.960: ERROR/ExternalAccountType(31657): Unsupported attribute readOnly
03-19 00:10:08.200: ERROR/MediaScannerService(13421): Exception scanning file
        android.os.DeadObjectException
        at android.os.BinderProxy.transact(Native Method)
        at android.media.IMediaScannerListener$Stub$Proxy.scanCompleted(IMediaScannerListener.java:100)
        at com.android.providers.media.MediaScannerService$ServiceHandler.handleMessage(MediaScannerService.java:1007)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:155)
        at com.android.providers.media.MediaScannerService.run(MediaScannerService.java:713)
        at java.lang.Thread.run(Thread.java:864)
03-19 00:10:10.270: ERROR/AndroidRuntime(23231): FATAL EXCEPTION: main
        java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
        at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
        at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
        at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:365)
        at android.app.Activity.setContentView(Activity.java:1912)
        at com.example.mapTest.MainActivity.onCreate(MainActivity.java:13)
        at android.app.Activity.performCreate(Activity.java:5066)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
        at android.app.ActivityThread.access$600(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:155)
        at android.app.ActivityThread.main(ActivityThread.java:5485)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
        at dalvik.system.NativeStart.main(Native Method)
03-19 00:10:10.285: ERROR/EmbeddedLogger(434): App crashed! Process: com.example.mapTest
03-19 00:10:10.285: ERROR/EmbeddedLogger(434): App crashed! Package: com.example.mapTest v1 (1.0)
03-19 00:10:10.285: ERROR/EmbeddedLogger(434): Application Label: mapTest

共有1个答案

贺兴昌
2023-03-14

您是否将Google Play服务库包含在您的项目中?没有它,关键的资源就无法获得。请参阅问题:java.lang.noClassDeffounderRor:com.google.android.gms.r$styleable了解更多详细信息。

 类似资料:
  • 下面给出的错误 process:com.example.rahul.maptask,pid:21986 java.lang.runtimeException:无法启动活动ComponentInfo{com.example.rahul.maptask/com.example.rahul.maptask.mainactivity}:java.lang.nullpointerException:试图在A

  • 我正在从导入geoJSON数据。jsons文件。它在某些文件上工作得很好,但在其他文件上就不行了。我认为我的文件有问题,但我在geojson lint和geojson.io上测试了它们,没有问题。 这是堆栈: 这是我非常简单的代码 这是我的一个JSON导致了这个错误 build.gradle(项目)和build.gradle(应用程序) 欢迎任何想法

  • 对于某些活动的意图是有效的,对于某些特定的活动意图是崩溃的,我已经改变并尝试了不同的方法,但是对于某些活动意图是无效的,应用程序正在构建,但是在手机上运行之后,它在调试期间没有显示出任何错误?我尝试了不同的方法,但它仍然崩溃,谁能帮助我解决它? MainActivity java 清单文件

  • 所以我目前正在努力开发一个应用程序,需要一个谷歌地图API。每当我尝试加载地图时,我的应用程序将我的地图实现为片段类的子类: 编辑:原来我只是错过了应该被引用的API键。我很抱歉提出了一个低质量的问题