0

我是 Android 开发的新手。我试图从此链接运行一个程序,显示如何使用 Google Map API

然而,在我按照这些步骤并尝试在 HTC 平板电脑上启动我的应用程序之后。我在平板电脑上收到错误“应用程序已意外停止”。我捕获了您可以在下面看到的 logcat 输出。如果有人可以帮助我解决这个问题,我真的很感激。

01-11 20:30:43.703: D/dalvikvm(14541): GC_CONCURRENT freed 245K, 48% free 2975K/5639K, external 0K/0K, paused 3ms+9ms
01-11 20:30:43.884: D/dalvikvm(14541): GC_CONCURRENT freed 542K, 50% free 2987K/5959K, external 0K/0K, paused 3ms+4ms
01-11 20:30:43.924: D/AndroidRuntime(14541): Shutting down VM
01-11 20:30:43.924: W/dalvikvm(14541): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
01-11 20:30:43.924: E/AndroidRuntime(14541): FATAL EXCEPTION: main
01-11 20:30:43.924: E/AndroidRuntime(14541): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemap/com.example.googlemap.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1840)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1861)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.app.ActivityThread.access$1500(ActivityThread.java:132)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.os.Looper.loop(Looper.java:150)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.app.ActivityThread.main(ActivityThread.java:4310)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at java.lang.reflect.Method.invokeNative(Native Method)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at java.lang.reflect.Method.invoke(Method.java:507)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at dalvik.system.NativeStart.main(Native Method)
01-11 20:30:43.924: E/AndroidRuntime(14541): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:255)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.app.Activity.setContentView(Activity.java:1728)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at com.example.googlemap.MainActivity.onCreate(MainActivity.java:16)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1804)
01-11 20:30:43.924: E/AndroidRuntime(14541):    ... 11 more
01-11 20:30:43.924: E/AndroidRuntime(14541): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.example.googlemap-2.apk]
01-11 20:30:43.924: E/AndroidRuntime(14541):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.view.LayoutInflater.createView(LayoutInflater.java:471)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
01-11 20:30:43.924: E/AndroidRuntime(14541):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
01-11 20:30:43.924: E/AndroidRuntime(14541):    ... 20 more

这是 Manifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemap"
android:versionCode="1"
android:versionName="1.0" >

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <uses-library android:name="com.google.android.maps" />
    <activity
        android:name="MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBjpVaza7xnJkK64dlFl0v0n3h9QowvcB0"/>

</application>

<permission
      android:name="com.example.googlemap.permission.MAPS_RECEIVE"
      android:protectionLevel="signature"/>
<uses-permission android:name="com.example.googlemap.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.INTERNET" />     
    <uses-feature
  android:glEsVersion="0x00020000"
  android:required="true"/>
</manifest>

这是 MainActivity.xml:

package com.example.googlemap;

import android.os.Bundle;
//import android.app.Activity;
import android.view.Menu;
//import android.view.MenuItem;
//import android.support.v4.app.NavUtils;
import com.google.android.maps.MapActivity;
//import com.google.android.maps.MapView;

public class MainActivity extends MapActivity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }


    @Override
    protected boolean isRouteDisplayed() {
        return false;
    } 

}

最后一个activity_main.xml:

package com.example.googlemap;

import android.os.Bundle;
//import android.app.Activity;
import android.view.Menu;
//import android.view.MenuItem;
//import android.support.v4.app.NavUtils;
import com.google.android.maps.MapActivity;
//import com.google.android.maps.MapView;

public class MainActivity extends MapActivity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }


    @Override
    protected boolean isRouteDisplayed() {
        return false;
    } 

}
4

1 回答 1

0

看来应该是android.app.Fragment,而不是android.app.fragment。01-11 20:30:43.924: E/AndroidRuntime(14541): 由: java.lang.ClassNotFoundException: android.view.fragment

编辑:误读您的代码。仍在寻找答案。

于 2013-01-12T05:54:50.960 回答