为什么我得到一个白色的屏幕地图应用程序 [英] Why i'm getting a white screen in map app
问题描述
我是新来的,也有新的节目。 我在做图,我已经跟着很多教程,他们都非常呈三角,但我不知道为什么我的应用程序无法正常工作。该应用程序不会崩溃,但是当我打开地图显示的应用程序标题和一个白色的屏幕,地图上就会出现。你知道为什么会出现这种情况?
I'm new here and also new in programming. I'm making map, I have followed a lot of tutorials, all of them very simillar but I don't know why my app doesn't work. The app doesn't crash, but when I open the map appears the app title and a white screen where the map should appear. Do you know why is this happening?
下面是我的应用程序清单,该活动:main.xml中和mainactivity.java,也许这里就是我找不到错误
Here are my app manifest, the activity:main.xml and the mainactivity.java, maybe here's the error that I can't find.
此外,如果帮助logcat的说我:错误打开跟踪文件:没有这样的文件或目录(2)
Also if helps logcat says me: Error opening trace file: No such file or directory (2)
APP清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tdr.mapa1"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.tdr.mapa1.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="permission_name"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.tdr.mapa1.permission.MAPS_RECEIVE"/>
<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"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<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"
android:required="false"/>
<activity
android:name="com.tdr.mapa1.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.google.android.maps.v2.API_KEY"
android:value="<API_KEY>"/>
</application>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</manifest>
主要活动
<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"
tools:context=".MainActivity" >
</RelativeLayout>
MAINACTIVITY.JAVA
MAINACTIVITY.JAVA
package com.tdr.mapa1;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
希望你能帮助我。
Hope you can help me.
推荐答案
首先你的错误:
Error opening trace file: No such file or directory (2)
并不意味着什么,你应该节点理会它。
doesn't mean anything and you should node pay any attention to it.
其次,无论是元数据标签应的应用范围内,像这样:
Second, both meta-data tags should be inside of the application scope, like so:
...
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="<API_KEY>"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
最后,你实际上并没有创造任何地图对象在活动布局文件,你有什么有一个空的 RelativeLayout的
,因此空的白色屏幕。你需要的是增加一个 MapFragment
在那里或 SupportMapFramgnet
这取决于你的目标的API。 (在你的情况下,这将是 MapFragment
)
Lastly, you are not actually creating any map object in your activity layout file, what you have there is an empty RelativeLayout
and hence the empty white screen. What you need is to add an MapFragment
in there or SupportMapFramgnet
depending on your target api. (In your case it would be MapFragment
.)
像这样:
<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"
tools:context=".MainActivity" >
<fragment
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
您可以从这篇博客我写了关于这一主题获得更详细的信息
Google Maps API V2 Guide
这篇关于为什么我得到一个白色的屏幕地图应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!