为什么我在地图应用程序中出现白屏 [英] 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?
这是我的应用清单、activity: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)
应用清单
<?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);
}
}
希望你能帮助我.
推荐答案
首先是你的错误:
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
,因此是空的白屏.您需要的是根据您的目标 api 在其中添加 MapFragment
或 SupportMapFramgnet
.(在您的情况下,它将是 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>
你可以从我写的关于这个主题的这篇博文中获得更详细的信息:
You can get more detailed information from this blog post I wrote on this topic:
这篇关于为什么我在地图应用程序中出现白屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!