android - 当我点击按钮(Intent)打开它时,谷歌地图在我的应用程序上崩溃

标签 android google-maps android-intent

我有一个 Android 应用程序,里面有一些 Activity ,其中包括谷歌地图 fragment ,我在主屏幕上有一个按钮来打开这个 map Activity ,当我点击按钮时,它只会让应用程序一直崩溃。

Bellow 是主类。

package com.test.finalproject;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.support.v4.app.FragmentActivity;

  public class MainActivity extends  ActionBarActivity implements View.OnClickListener {

Button buttonLogin;
Button buttonRegister;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    buttonLogin = (Button)findViewById(R.id.buttonLogin);
    buttonLogin.setOnClickListener(this);
    buttonLogin = (Button)findViewById(R.id.buttonRegister);
    buttonLogin.setOnClickListener(this);
}

private void buttonLoginClick()
{
    startActivity (new Intent("GoogleMaps"));
}

private void buttonRegisterClick()
{
    startActivity (new Intent("TextToo"));
}

@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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}



@Override
public void onClick(View v) {
    switch (v.getId())
    {
        case R.id.buttonLogin:
            buttonLoginClick();
            break;

    }
    switch (v.getId())
    {
    case R.id.buttonRegister:
        buttonRegisterClick();
        break;
        }
    }
  }

这是布局 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:orientation="vertical">

<TextView
    android:background="@null"
    android:editable="false"
    android:cursorVisible="false"

    />

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

</RelativeLayout>

这是 list 。

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

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

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
    android:name="com.test.finalproject.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.test.finalproject.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gfs.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_FINE_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" >
    <uses-library android:name="com.google.android.maps" />
    <activity android:name="com.facebook.LoginActivity" >
    </activity>
    <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>

    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyB1_6ny8uuUeslw566zO6ghBCOE3_rxklE" />

    <activity
        android:name=".MainApp"
        android:label="@string/title_activity_main_app" >
        <intent-filter>
            <action android:name="MainApp" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Register"
        android:label="@string/title_activity_register" >
        <intent-filter>
            <action android:name="Register" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name=".GoogleMaps"
        android:label="@string/title_activity_google_maps" >
        <intent-filter>
            <action android:name="GoogleMaps" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name=".TextTo"
        android:label="@string/title_activity_text_to" >
        <intent-filter>
            <action android:name="TextToo" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
   </application>

</manifest>

GoogleMaps Activity :

package com.test.finalproject;

import com.google.android.maps.MapActivity;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;

public class GoogleMaps extends MapActivity {

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

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
   }
}

This is an image of the log, it has a lot more than that underneath it I just don't know how to export it, I have searched this for days and tried so many different solutions that didn't work. Please help me if you can, Thanks you.

编辑:我没有足够的声望来发布图片:(

编辑:LogCat;

     11-11 10:50:55.196: I/Process(15717): Sending signal. PID: 15717 SIG: 9
11-11 10:50:55.926: I/PersonaManager(15873): getPersonaService() name persona_policy
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:48 height:48 bitmap id is 180 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:13 height:41 bitmap id is 181 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:48 height:48 bitmap id is 182 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:72 height:72 bitmap id is 183 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:18 height:18 bitmap id is 184 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:72 height:72 bitmap id is 185 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:18 height:18 bitmap id is 186 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:72 height:72 bitmap id is 187 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:72 height:72 bitmap id is 188 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:72 height:72 bitmap id is 189 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 190 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 191 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 192 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 193 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 194 
11-11 10:50:55.956: D/skia(15873): GFXPNG PNG bitmap created width:21 height:93 bitmap id is 195 
11-11 10:50:55.966: D/skia(15873): GFXPNG PNG bitmap created width:18 height:18 bitmap id is 196 
11-11 10:50:55.966: D/skia(15873): GFXPNG PNG bitmap created width:21 height:93 bitmap id is 197 
11-11 10:50:55.966: D/skia(15873): GFXPNG PNG bitmap created width:21 height:93 bitmap id is 198 
11-11 10:50:55.966: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 199 
11-11 10:50:55.966: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 200 
11-11 10:50:55.966: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 201 
11-11 10:50:55.966: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 202 
11-11 10:50:55.966: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 203 
11-11 10:50:55.966: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 204 
11-11 10:50:55.966: D/skia(15873): GFXPNG PNG bitmap created width:40 height:40 bitmap id is 205 
11-11 10:50:55.966: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 206 
11-11 10:50:55.966: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 207 
11-11 10:50:55.966: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 208 
11-11 10:50:55.966: D/skia(15873): GFXPNG PNG bitmap created width:78 height:96 bitmap id is 209 
11-11 10:50:55.976: D/skia(15873): GFXPNG PNG bitmap created width:96 height:96 bitmap id is 210 
11-11 10:50:55.976: D/skia(15873): GFXPNG PNG bitmap created width:144 height:144 bitmap id is 211 
11-11 10:50:55.976: E/MoreInfoHPW_ViewGroup(15873): Parent view is not a TextView
11-11 10:50:56.036: I/Adreno-EGL(15873): <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build:  ()
11-11 10:50:56.036: I/Adreno-EGL(15873): OpenGL ES Shader Compiler Version: E031.24.00.08+13
11-11 10:50:56.036: I/Adreno-EGL(15873): Build Date: 03/20/14 Thu
11-11 10:50:56.036: I/Adreno-EGL(15873): Local Branch: 0320_AU200_patches
11-11 10:50:56.036: I/Adreno-EGL(15873): Remote Branch: 
11-11 10:50:56.036: I/Adreno-EGL(15873): Local Patches: 
11-11 10:50:56.036: I/Adreno-EGL(15873): Reconstruct Branch: 
11-11 10:50:56.066: D/OpenGLRenderer(15873): Enabling debug mode 0
11-11 10:50:56.186: I/System.out(15873): Thread-15991(HTTPLog):isShipBuild true
11-11 10:50:56.186: I/System.out(15873): Thread-15991(HTTPLog):SmartBonding Enabling is true, SHIP_BUILD is true, log to file is false, DBG is false
11-11 10:50:56.946: I/PersonaManager(15873): getPersonaService() name persona_policy
11-11 10:50:56.976: E/MoreInfoHPW_ViewGroup(15873): Parent view is not a TextView
11-11 10:50:56.996: I/u(15873): Making Creator dynamically
11-11 10:50:56.996: I/Google Maps Android API(15873): Google Play services client version: 6171000
11-11 10:50:57.006: I/Google Maps Android API(15873): Google Play services package version: 6188038
11-11 10:50:57.426: D/REQUEST(15873): Using server: https://clients4.google.com/glm/mmap/api
11-11 10:50:57.426: D/AndroidRuntime(15873): Shutting down VM
11-11 10:50:57.426: W/dalvikvm(15873): threadid=1: thread exiting with uncaught exception (group=0x4182ada0)
11-11 10:50:57.436: E/AndroidRuntime(15873): FATAL EXCEPTION: main
11-11 10:50:57.436: E/AndroidRuntime(15873): Process: com.test.finalproject, PID: 15873
11-11 10:50:57.436: E/AndroidRuntime(15873): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.finalproject/com.test.finalproject.GoogleMaps}: android.view.InflateException: Binary XML file line #16: Error inflating class fragment
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2394)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2452)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.app.ActivityThread.access$900(ActivityThread.java:172)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1302)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.os.Handler.dispatchMessage(Handler.java:102)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.os.Looper.loop(Looper.java:136)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.app.ActivityThread.main(ActivityThread.java:5586)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at java.lang.reflect.Method.invokeNative(Native Method)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at java.lang.reflect.Method.invoke(Method.java:515)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at dalvik.system.NativeStart.main(Native Method)
11-11 10:50:57.436: E/AndroidRuntime(15873): Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class fragment
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:350)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.app.Activity.setContentView(Activity.java:2031)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.test.finalproject.GoogleMaps.onCreate(GoogleMaps.java:15)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.app.Activity.performCreate(Activity.java:5451)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
11-11 10:50:57.436: E/AndroidRuntime(15873):    ... 11 more
11-11 10:50:57.436: E/AndroidRuntime(15873): Caused by: java.lang.SecurityException: The Maps API requires the additional following permissions to be set in the AndroidManifest.xml to ensure a correct behavior:
11-11 10:50:57.436: E/AndroidRuntime(15873): <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.google.maps.api.android.lib6.c.ca.a(Unknown Source)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.google.maps.api.android.lib6.c.c.a(Unknown Source)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.google.maps.api.android.lib6.c.dw.a(Unknown Source)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.google.maps.api.android.lib6.c.v.a(Unknown Source)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.google.maps.api.android.lib6.c.u.a(Unknown Source)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.google.android.gms.maps.internal.u.onTransact(SourceFile:107)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.os.Binder.transact(Binder.java:361)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.google.android.gms.maps.MapFragment$a.onCreateView(Unknown Source)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.google.android.gms.dynamic.a$4.b(Unknown Source)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.google.android.gms.dynamic.a.a(Unknown Source)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.app.Fragment.performCreateView(Fragment.java:1700)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:866)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1040)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1142)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.app.Activity.onCreateView(Activity.java:4997)
11-11 10:50:57.436: E/AndroidRuntime(15873):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
11-11 10:50:57.436: E/AndroidRuntime(15873):    ... 21 more

最佳答案

您遇到异常:

Trying to instantiate a class com.google.android.gms.maps.SupportMapFragment that is not a Fragment –Caused by: java.lang.ClassCastException

您正在使用 MapActivity:GoogleMaps extends MapActivity 意味着您需要处理 MapFragment 而不是 SupportMapFragment

您可以通过两种方式处理此问题:

1.SupportMapFragment 替换为 MapFragment

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

在这种情况下,您需要导入:

import android.app.Fragment;
import android.app.FragmentTransaction;

2.MapActivity替换为FragmentActivity

在这种情况下,您需要导入:

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

关于android - 当我点击按钮(Intent)打开它时,谷歌地图在我的应用程序上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26857069/

相关文章:

Android 手机锁屏时电源键按下事件启动后台服务

android - 奇怪的 Activity 生命周期。

ListView 中的Android不同行

java - 在 android 派中重新启动应用程序时,sqlite 中输入的数据会自动删除

android - 标记消失

java - latlng 不能为空 - 自动完成中需要一个位置

android - 如何在android中将动态字符串设置为用户选择?

android - 替换默认的 Android Maps API v2 更改 MyLocation 图标

android - 如何使用 HTML url 加载新窗口?在安卓系统中

Android - 短信广播接收器