我尝试在我的应用程序上显示谷歌地图,但我不能 这是错误
01-17 03:54:14.312: E/AndroidRuntime(1355): FATAL EXCEPTION: main
01-17 03:54:14.312: E/AndroidRuntime(1355): java.lang.NullPointerException
01-17 03:54:14.312: E/AndroidRuntime(1355): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1374)
01-17 03:54:14.312: E/AndroidRuntime(1355): at android.app.Activity.startActivityForResult(Activity.java:2827)
01-17 03:54:14.312: E/AndroidRuntime(1355): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839)
01-17 03:54:14.312: E/AndroidRuntime(1355): at android.app.Activity.startActivity(Activity.java:2933)
01-17 03:54:14.312: E/AndroidRuntime(1355): at com.google.android.gms.dynamic.a$5.onClick(Unknown Source)
01-17 03:54:14.312: E/AndroidRuntime(1355): at android.view.View.performClick(View.java:2485)
01-17 03:54:14.312: E/AndroidRuntime(1355): at android.view.View$PerformClick.run(View.java:9080)
01-17 03:54:14.312: E/AndroidRuntime(1355): at android.os.Handler.handleCallback(Handler.java:587)
01-17 03:54:14.312: E/AndroidRuntime(1355): at android.os.Handler.dispatchMessage(Handler.java:92)
01-17 03:54:14.312: E/AndroidRuntime(1355): at android.os.Looper.loop(Looper.java:130)
01-17 03:54:14.312: E/AndroidRuntime(1355): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-17 03:54:14.312: E/AndroidRuntime(1355): at java.lang.reflect.Method.invokeNative(Native Method)
01-17 03:54:14.312: E/AndroidRuntime(1355): at java.lang.reflect.Method.invoke(Method.java:507)
01-17 03:54:14.312: E/AndroidRuntime(1355): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-17 03:54:14.312: E/AndroidRuntime(1355): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-17 03:54:14.312: E/AndroidRuntime(1355): at dalvik.system.NativeStart.main(Native Method)
的manifest.xml 我添加了我在互联网上发现的所有权利,而我认为问题不在这里
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flow"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="18" />
<permission
android:name="com.example.flow.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-permission android:name="com.example.flow.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<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="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.flow.Flow"
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.google.android.maps.v2.API_KEY"
android:value="AIzaSyDNIkpmmuFyj2vpTfAPtnqWpf-EX94bRl0"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
activity_flow.xml 添加片段和SupportMapFragment
<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=".Flow" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<fragment
android:id="@+id/map1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
flow.java
package com.example.flow;
import com.google.android.gms.maps.GoogleMap;
import android.os.Bundle;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
public class Flow extends FragmentActivity {
GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flow);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}
答案 0 :(得分:0)
我想从这一行at android.app.Activity.startActivityForResult(Activity.java:2827)
您可能忘记在您的课程中实施onActivityResult
方法。确保您是否以startActivityForResult()
开始活动,那么您必须实施此方法。
答案 1 :(得分:0)
确保你的清单
<permission
android:name="com.example.flow.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.flow.permission.MAPS_RECEIVE"/>
还要确保在maps api控制台中设置了密钥(调试或发布)。
答案 2 :(得分:0)
一旦浏览this链接,我在另一篇帖子中回答了这个链接..
它可以帮助你。如果您有任何疑问,请告诉我。