【问题标题】:google map eclipse not working on my emulator谷歌地图日食无法在我的模拟器上运行
【发布时间】:2014-05-08 09:59:27
【问题描述】:

我花了很多时间搜索我的问题的一些答案,但我开始了很短的时间编码,但我的代码没有成功。所以我请求你的帮助。非常感谢!

所以当我运行我的程序时它可以工作(没有项目错误)但在我的模拟器上它不起作用,我在 logcat 中有这个错误

我的日志猫

*05-08 04:53:04.448: E/AndroidRuntime(1057): FATAL EXCEPTION: main
05-08 04:53:04.448: E/AndroidRuntime(1057): Process: com.example.carte, PID: 1057
05-08 04:53:04.448: E/AndroidRuntime(1057): java.lang.RuntimeException: Unable to start         activity ComponentInfo{com.example.carte/com.example.carte.MainActivity}:  java.lang.NullPointerException
05-08 04:53:04.448: E/AndroidRuntime(1057):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at android.os.Handler.dispatchMessage(Handler.java:102)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at android.os.Looper.loop(Looper.java:136)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at android.app.ActivityThread.main(ActivityThread.java:5017)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at java.lang.reflect.Method.invokeNative(Native Method)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at java.lang.reflect.Method.invoke(Method.java:515)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at dalvik.system.NativeStart.main(Native Method)
05-08 04:53:04.448: E/AndroidRuntime(1057): Caused by: java.lang.NullPointerException
05-08 04:53:04.448: E/AndroidRuntime(1057):     at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at com.example.carte.MainActivity.onCreate(MainActivity.java:34)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at android.app.Activity.performCreate(Activity.java:5231)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-08 04:53:04.448: E/AndroidRuntime(1057):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)*

正如我所说,我试图找到解决方案:我添加了

 <uses-library android:name="com.google.android.maps" />

在我的 android 清单中,所有错误都消失了,但仍然存在错误

 enter code here`"INSTALL_FAILED_MISSING_SHARED_LIBRARY". 

我的 MainActivity.java

package com.example.carte;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;




import com.example.carte.R;
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.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;

public class MainActivity extends ActionBarActivity {


  static final LatLng HAMBURG = new LatLng(53.568, 9.927);
  static final LatLng KIEL = new LatLng(53.551, 9.993);
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.fragment_main);
    super.onCreate(savedInstanceState);

    GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                .getMap();

            if (map!=null){
              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)));
            }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container,
                false);
        return rootView;
    }
}

}

我的 AndroidManifest.xml

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

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

 <uses-permission android:name="com.vogella.android.locationapi.maps.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_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application

    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.carte.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="A----------------------------" />


</application>

我在 Android SDK 管理器中添加了 google 库并下载了所有 google extras。

我是法国人,所以我请你原谅我的英语......并原谅我的页面布局,这对我来说是第一次,我尽力做到最好。感谢您的帮助

【问题讨论】:

    标签: java android eclipse android-emulator


    【解决方案1】:

    尝试遵循本指南: https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2

    对 Maps V2 来说同样重要的是签署您的项目:

    http://developer.android.com/tools/publishing/app-signing.html

    从我在这里快速阅读的内容看来,您应该使用您的密钥来签署您的项目,而不是在清单中。以下内容应在您的清单中,而不是 API 密钥中:

    <meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
    

    【讨论】:

    • 我成功了,你是对的,我添加了你所说的,我严格按照链接!谢谢!!!
    • 没问题:)。你能不能把这个作为答案,所以问题就结束了。
    【解决方案2】:

    您应该尝试使用其他一些模拟器选项,而不是尝试测试您的应用程序,例如

    https://cloud.genymotion.com/page/launchpad/download/http://www.bluestacks.com/

    【讨论】:

      【解决方案3】:

      不幸的是,使用 Google 地图您必须在真实设备上测试应用程序,因为不支持模拟器。

      如果您对此有更多详细信息,请阅读Google Maps Android API v2 - Tutorial

      【讨论】:

        猜你喜欢
        • 2012-12-10
        • 2013-08-07
        • 2014-03-15
        • 2011-07-02
        • 2010-11-09
        • 2014-09-04
        • 2018-05-19
        • 2013-10-22
        • 2012-07-25
        相关资源
        最近更新 更多