我已经尝试过在我的应用程序中实现Google Maps的教程.
http://www.androidhive.info/2013/08/android-working-with-google-maps-v2/
我会尝试这个例子,但它在这个级别崩溃:setContentVIEw(R.layout.activity_main);
我正确地遵循tuto,通常没有API Key问题.
编辑:这是我所有已解决的代码 – 错误显示在评论中
MANIFEST.XML:
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="com.example.essaimap" androID:versionCode="1" androID:versionname="1.0" > <permission androID:name="com.example.essaimap.permission.MAPS_RECEIVE" androID:protectionLevel="signature" /> <uses-permission androID:name="com.example.essaimap.permission.MAPS_RECEIVE" /> <uses-sdk androID:minSdkVersion="11" androID:targetSdkVersion="16" /> <uses-permission androID:name="androID.permission.ACCESS_NETWORK_STATE" /> <uses-permission androID:name="androID.permission.INTERNET" /> <uses-permission androID:name="com.Google.androID.provIDers.gsf.permission.READ_GSERVICES" /> <uses-permission androID:name="androID.permission.WRITE_EXTERNAL_STORAGE" /> <!-- required to show current location --> <uses-permission androID:name="androID.permission.ACCESS_COARSE_LOCATION" /> <uses-permission androID:name="androID.permission.ACCESS_FINE_LOCATION" /> <!-- required OpenGL ES 2.0. for Maps V2 --> <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" > <!-- important ! DO NOT FORGET THIS Meta-DATA !!! --> <Meta-data androID:name="com.Google.androID.gms.version" androID:value="@integer/Google_play_services_version" /> <!-- important ! DO NOT PUT THIS Meta IN ACTIVITY ELEMENT--> <Meta-data androID:name="com.Google.androID.maps.v2.API_KEY" androID:value="AIzaSyDWCZGT4OIUAZEOUIYAZEOIYAZOEIYAZOEIY6WRvbh6BnHSAipgg" /> <activity androID:name="com.example.essaimap.MainActivity" androID:label="@string/app_name" > <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> <!-- I put my Meta here, that is why my app was crashing <Meta-data androID:name="com.Google.androID.maps.v2.API_KEY" androID:value="AIzaSyDWCZGT4n2HLZ5bUCM6WRvbh6BnHSAipgg" /> --> </activity> </application></manifest>
ACTIVITY_MAIN.XML:
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="fill_parent"androID:layout_height="fill_parent" > <fragment androID:ID="@+ID/map" androID:name="com.Google.androID.gms.maps.MapFragment" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"/></relativeLayout>
MAINACTIVITY.JAVA:
public class MainActivity extends FragmentActivity // Not ACTIVITY{ // Google Map private GoogleMap GoogleMap; protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); try { // Loading map initilizeMap(); } catch (Exception e) { e.printstacktrace(); } } /** * function to load map. If map is not created it will create it for you * */ private voID initilizeMap() { if (GoogleMap == null) { GoogleMap = ((MapFragment) getFragmentManager().findFragmentByID(R.ID.map)).getMap(); // check if map is created successfully or not if (GoogleMap == null) { Toast.makeText(getApplicationContext(),"Sorry! unable to create maps",Toast.LENGTH_SHORT).show(); } } } protected voID onResume() { super.onResume(); initilizeMap(); }}
logcat的
感谢@Piyush Gupta,@ fasteque,@ WarrenFaith,@ Sankar V和@ViragBrahme解决了我的问题.
Tofuw
解决方法:
您在清单文件中缺少新的强制元标记,它是在logcat中编写的.
在清单文件的应用程序部分中添加以下行:
<Meta-data androID:name="com.Google.androID.gms.version" androID:value="@integer/Google_play_services_version" />
此外,您的清单中还有另一个问题,您已在活动中复制了元标记com.Google.androID.maps.v2.API_KEY,同时也应在应用程序部分进行设置.
总结以上是内存溢出为你收集整理的java – Google Maps API V2崩溃 – 致命异常全部内容,希望文章能够帮你解决java – Google Maps API V2崩溃 – 致命异常所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)