Android地图应用程序无法正常工作

时间:2014-04-17 14:23:47

标签: java android eclipse google-maps google-maps-android-api-2

我正在制作一个简单的地图应用程序并使用谷歌地图api v2 ....

min sdk是:android 2.2 froyo api 8 target sdk是:android 4.4 kitkat api 19 用平台编译:android 4.4 kitkat api 19

我按照youtube教程完成所有工作,但仍在执行应用程序时,我收到一条消息,对不起,您的应用程序com.example.margallahillhikedroid已意外停止"

以下是我的清单文件代码:

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

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

<permission android:name="com.example.margallahillhikedroid.permission.MAPS_RECEIVE" 
android:protectionLevel="signature"/>
<uses-permission android:name="your.application.package.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-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="my api key" />

    <activity
        android:name="com.example.margallahillhikedroid.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>

以下是xml的文件代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

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

</RelativeLayout>

以下是java文件的代码;

package com.example.margallahillhikedroid;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

以下是LOG cat中的错误:

03-24 07:49:18.152: D/AndroidRuntime(1922): Shutting down VM
03-24 07:49:18.152: W/dalvikvm(1922): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
03-24 07:49:18.172: E/AndroidRuntime(1922): FATAL EXCEPTION: main//error starts from here
03-24 07:49:18.172: E/AndroidRuntime(1922): java.lang.RuntimeException: Unable to start activity 

//log cat errors..............................//

ComponentInfo{com.example.margallahillhikedroid/com.example.margallahillhikedroid.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment// error is not understandable

03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.os.Looper.loop(Looper.java:123)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.app.ActivityThread.main(ActivityThread.java:4627)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at java.lang.reflect.Method.invokeNative(Native Method)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at java.lang.reflect.Method.invoke(Method.java:521)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at dalvik.system.NativeStart.main(Native Method)
03-24 07:49:18.172: E/AndroidRuntime(1922): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.app.Activity.setContentView(Activity.java:1647)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at com.example.margallahillhikedroid.MainActivity.onCreate(MainActivity.java:12)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-24 07:49:18.172: E/AndroidRuntime(1922):     ... 11 more
03-24 07:49:18.172: E/AndroidRuntime(1922): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.margallahillhikedroid-2.apk]
03-24 07:49:18.172: E/AndroidRuntime(1922):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at  android.view.LayoutInflater.createView(LayoutInflater.java:466)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
03-24 07:49:18.172: E/AndroidRuntime(1922):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
03-24 07:49:18.172: E/AndroidRuntime(1922):     ... 20 more
03-24 07:49:30.772: I/Process(1922): Sending signal. PID: 1922 SIG: 9

2 个答案:

答案 0 :(得分:0)

SupportMapFragment的xml中你应该写:

class="com.google.android.gms.maps.SupportMapFragment"

而不是:

android:name="com.google.android.gms.maps.SupportMapFragment"

另见上面链接文档中的发布示例。你也应该使用FragmentActivity而不是Activity ..

答案 1 :(得分:0)

我不确定它是否仍未解决,但您应该在设备上更新Google Play服务。