简体   繁体   English

Android 2.3.3和Google Maps API v2错误启动活动

[英]Android 2.3.3 and google maps api v2 error starting activity

I have such activityclass code: 我有这样的活动类代码:

package com.pavel.exchanger;

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import android.support.v4.app.Fragment;


public class SearchExchangerActivity extends FragmentActivity   {
    static final LatLng HAMBURG = new LatLng(53.558, 9.927);
    static final LatLng KIEL = new LatLng(53.551, 9.993);
    private GoogleMap map;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_exchanger);

        map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                .getMap();
            Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
                .title("Hamburg"));
            Marker kiel = map.addMarker(new MarkerOptions()
                .position(KIEL)
                .title("Kiel")
                .snippet("Kiel is cool")
                .icon(BitmapDescriptorFactory
                    .fromResource(R.drawable.ic_launcher)));

            // Move the camera instantly to hamburg with a zoom of 15.
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

            // Zoom in, animating the camera.
            map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
    }

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

}

and such layout: 以及这样的布局:

<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=".SearchExchangerActivity" >

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"/>

</RelativeLayout> 

and such manifest: 这样的清单:

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

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.pavel.exchanger.permission.MAPS_RECEIVE" />
    <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" />

    <permission
        android:name="com.pavel.exchanger.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.pavel.exchanger.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>
        <activity
            android:name="com.pavel.exchanger.ExchangerListActivity"
            android:label="@string/title_activity_exchanger_list" >
        </activity>
        <activity
            android:name="com.pavel.exchanger.BankExchangersListActivity"
            android:label="@string/title_activity_bank_exchangers_list" >
        </activity>
        <activity
            android:name="com.pavel.exchanger.NbrbActivity"
            android:label="@string/title_activity_nbrb" >
        </activity>

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

        <activity
            android:name="com.pavel.exchanger.SearchExchangerActivity"
            android:label="@string/title_activity_search_exchanger" >
        </activity>
    </application>

</manifest>

but when i run my activity i get: 但是当我进行活动时,我得到:

04-30 21:39:32.856: E/AndroidRuntime(435): FATAL EXCEPTION: main
04-30 21:39:32.856: E/AndroidRuntime(435): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pavel.exchanger/com.pavel.exchanger.SearchExchangerActivity}: java.lang.NullPointerException
04-30 21:39:32.856: E/AndroidRuntime(435):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-30 21:39:32.856: E/AndroidRuntime(435):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-30 21:39:32.856: E/AndroidRuntime(435):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-30 21:39:32.856: E/AndroidRuntime(435):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-30 21:39:32.856: E/AndroidRuntime(435):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-30 21:39:32.856: E/AndroidRuntime(435):  at android.os.Looper.loop(Looper.java:123)
04-30 21:39:32.856: E/AndroidRuntime(435):  at android.app.ActivityThread.main(ActivityThread.java:3683)
04-30 21:39:32.856: E/AndroidRuntime(435):  at java.lang.reflect.Method.invokeNative(Native Method)
04-30 21:39:32.856: E/AndroidRuntime(435):  at java.lang.reflect.Method.invoke(Method.java:507)
04-30 21:39:32.856: E/AndroidRuntime(435):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-30 21:39:32.856: E/AndroidRuntime(435):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-30 21:39:32.856: E/AndroidRuntime(435):  at dalvik.system.NativeStart.main(Native Method)
04-30 21:39:32.856: E/AndroidRuntime(435): Caused by: java.lang.NullPointerException
04-30 21:39:32.856: E/AndroidRuntime(435):  at com.pavel.exchanger.SearchExchangerActivity.onCreate(SearchExchangerActivity.java:29)
04-30 21:39:32.856: E/AndroidRuntime(435):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-30 21:39:32.856: E/AndroidRuntime(435):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-30 21:39:32.856: E/AndroidRuntime(435):  ... 11 more

all lib's and project (google play) are included.... 包括所有库和项目(Google Play)。

But why i'm getting this error's? 但是为什么我会收到这个错误呢? How can i see google map on 2.3.3??? 我如何在2.3.3上看到Google地图???

Also if i do such code in activity (default): 另外,如果我在活动中执行此类代码(默认):

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_exchanger);  
    }

in emulator i see that i need to install google play app.... 在模拟器中,我看到我需要安装Google Play应用。

How to run google maps api v2 on android 2.3.3??? 如何在Android 2.3.3上运行Google Maps API v2 ???

Google Play services is not supported on the Android emulator — to develop using the APIs, you need to provide a development device such as an Android phone or tablet. Android模拟器不支持Google Play服务-要使用API​​进行开发,您需要提供开发设备,例如Android手机或平板电脑。

The above quote from http://developer.android.com/google/play-services/setup.html . 以上引用来自http://developer.android.com/google/play-services/setup.html

I suggest you run your app on your device. 建议您在设备上运行应用。

EDIT: 编辑:

If you are targeting an application earlier than API level 12, you can access the same functionality through the SupportMapFragment class. 如果您要定位API级别12之前的应用程序,则可以通过SupportMapFragment类访问相同的功能。 You will also have to include the Support Library. 您还必须包括支持库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM