0

I am new with android developing and whenever i am trying to start this activity it crashes. I've already tried with only hello world and the intent is fine, I am thinking it might be something in the Manifest but I am not sure of how it should be formed with maps api v2. I find this problem really frustrating. Any help is much appreciated. Manifest XML:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eriklansner.androidprojekt.alkometer"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="17" />

<permission
    android:name="com.eriklansner.androidprojekt.alkometer.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<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" >
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action
                android:name="android.intent.action.MAIN"
                android:value="your_apikey" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Promilleutraknaren"
        android:label="@string/title_activity_promilleutraknaren" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Activity"
        android:label="@string/title_activity_" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.MainActivityasd"
        android:label="@string/title_activity_main_activityasd" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Activitydos"
        android:label="@string/title_activity_activitydos" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Gelok"
        android:label="@string/title_activity_gelok" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.UseGps"
        android:label="@string/title_activity_use_gps" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Visasvar"
        android:label="@string/title_activity_visasvar" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.DataContentProvider"
        android:label="@string/title_activity_data_content_provider" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.ColumnSchema"
        android:label="@string/title_activity_column_schema" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.TemperatureData"
        android:label="@string/title_activity_temperature_data" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.MyActivity"
        android:label="@string/title_activity_my" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.MyPlot"
        android:label="@string/title_activity_my_plot" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.SimpleXYPlotActivity"
        android:label="@string/title_activity_simple_xyplot" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Main"
        android:label="@string/title_activity_main" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Alkinmatning"
        android:label="@string/title_activity_alkinmatning" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Alk"
        android:label="@string/title_activity_alk" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Googlemapsgps"
        android:label="@string/title_activity_googlemapsgps" >
    </activity>

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyDPaANagQvfdHSS0oFSmsrOsrr3sYVqs5E" />

    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.trolol"
        android:label="@string/title_activity_trolol" >
    </activity>
    <activity
        android:name="com.eriklansner.androidprojekt.alkometer.Map"
        android:label="@string/title_activity_map" >
    </activity>
</application>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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" />

activity_map.xml:

     <?xml version="1.0" encoding="utf-8"?>
     <fragment xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.google.android.gms.maps.MapFragment"/>

Map.java:

public class Map extends Activity {

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

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

}

4

1 回答 1

0

崩溃的可能原因。

您正在尝试在模拟器中运行它。

您没有在您的 Manifest.in 应用程序标签中包含 API 密钥。

 <application>
 <!-- some other code in the manifest -->
  <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="YOUR_API_KEY"/>
</application>

将地图片段添加到您的 Main.java

GoogleMap googleMap;
  // Getting reference to the SupportMapFragment of activity_main.xml
  MapFragment fm = (MapFragment) getFragmentManager().findFragmentById(R.id.map);

    // Getting GoogleMap object from the fragment
    googleMap = fm.getMap();

有关更多详细信息,请参阅我的博客文章,我试图总结使用适用于 Android 的 Google Maps API V2 构建应用程序所需的所有内容。

  1. Maps API V2 问题的解决方案(使用 google_play_services_lib)。
  2. 使用 Maps API V2 for minSDK=8 (Android 2.2 Froyo) 创建一个 Android 应用程序。
  3. 使用 Maps API V2 for minSDK=11 (Android 3.0 HoneyComb) 创建一个 Android 应用程序。

如果你想在模拟器上运行它,请阅读这篇文章。

于 2013-05-06T16:07:30.793 回答