Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 这里没有';无法在真实设备中显示_Java_Android_Google Maps_Android Studio_Here Api - Fatal编程技术网

Java 这里没有';无法在真实设备中显示

Java 这里没有';无法在真实设备中显示,java,android,google-maps,android-studio,here-api,Java,Android,Google Maps,Android Studio,Here Api,我尝试在Android studio中使用heremap制作一个简单的应用程序。但它不会显示在设备中。我下载了heremap api并将其jar添加到我的项目中。你能帮我吗 AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.l

我尝试在Android studio中使用heremap制作一个简单的应用程序。但它不会显示在设备中。我下载了heremap api并将其jar添加到我的项目中。你能帮我吗

AndroidManifest.xml

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

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.lojika.helloheremaps.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.here.android.maps.appid"
            android:value="XXXXXXXXXXXXXXXXXXXXXX"/>
        <meta-data android:name="com.here.android.maps.apptoken"
            android:value="XXXXXXXXXXXXXXXXXXXXXX"/>

        <service
            android:name="com.here.android.mpa.service.MapService"
            android:label="HereMapService"
            android:process="global.Here.Map.Service.v2"
            android:exported="true" >
            <intent-filter>
                <action android:name="com.here.android.mpa.service.MapService" >
                </action>
            </intent-filter>
        </service>
    </application>

</manifest>
package com.example.lojika.helloheremaps;

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

import com.here.android.mpa.common.MapActivity;
import com.here.android.mpa.common.GeoCoordinate;
import com.here.android.mpa.common.OnEngineInitListener;
import com.here.android.mpa.mapping.Map;
import com.here.android.mpa.mapping.MapFragment;


public class MainActivity extends Activity {

    // map embedded in the map fragment
    private Map map = null;

    // map fragment embedded in this activity
    private MapFragment mapFragment = null;

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

        // Search for the map fragment to finish setup by calling init().
        mapFragment = (MapFragment) getFragmentManager().findFragmentById( R.id.mapfragment);


        mapFragment.init(new OnEngineInitListener() {
            @Override
            public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
                if (error == OnEngineInitListener.Error.NONE) {
                    // retrieve a reference of the map from the map fragment
                    onMapFragmentInitializationCompleted();
                   // map = mapFragment.getMap();
                    // Set the map center to the Vancouver region (no animation)
                    //map.setCenter(new GeoCoordinate(15.1447, 120.5957, 0.0), Map.Animation.NONE);
                    // Set the zoom level to the average between min and max
                    //map.setZoomLevel(
                           // (map.getMaxZoomLevel() + map.getMinZoomLevel()) / 2);
                } else {
                    System.out.println("ERROR: Cannot initialize Map Fragment");
                }
            }
        });

    }
    private void onMapFragmentInitializationCompleted() {
        // retrieve a reference of the map from the map fragment
        map = mapFragment.getMap();
        // Set the map center coordinate to the Vancouver region (no animation)
        map.setCenter(new GeoCoordinate(49.196261, -123.004773, 0.0),
                Map.Animation.NONE);
        // Set the map zoom level to the average between min and max (no
        // animation)
        map.setZoomLevel((map.getMaxZoomLevel() + map.getMinZoomLevel()) / 2);
    }


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

}
 <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />

    <!-- Map Fragment embedded with the map object -->
    <fragment
        class="com.here.android.mpa.mapping.MapFragment"
        android:id="@+id/mapfragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>
活动\u main.xml

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

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.lojika.helloheremaps.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.here.android.maps.appid"
            android:value="XXXXXXXXXXXXXXXXXXXXXX"/>
        <meta-data android:name="com.here.android.maps.apptoken"
            android:value="XXXXXXXXXXXXXXXXXXXXXX"/>

        <service
            android:name="com.here.android.mpa.service.MapService"
            android:label="HereMapService"
            android:process="global.Here.Map.Service.v2"
            android:exported="true" >
            <intent-filter>
                <action android:name="com.here.android.mpa.service.MapService" >
                </action>
            </intent-filter>
        </service>
    </application>

</manifest>
package com.example.lojika.helloheremaps;

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

import com.here.android.mpa.common.MapActivity;
import com.here.android.mpa.common.GeoCoordinate;
import com.here.android.mpa.common.OnEngineInitListener;
import com.here.android.mpa.mapping.Map;
import com.here.android.mpa.mapping.MapFragment;


public class MainActivity extends Activity {

    // map embedded in the map fragment
    private Map map = null;

    // map fragment embedded in this activity
    private MapFragment mapFragment = null;

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

        // Search for the map fragment to finish setup by calling init().
        mapFragment = (MapFragment) getFragmentManager().findFragmentById( R.id.mapfragment);


        mapFragment.init(new OnEngineInitListener() {
            @Override
            public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
                if (error == OnEngineInitListener.Error.NONE) {
                    // retrieve a reference of the map from the map fragment
                    onMapFragmentInitializationCompleted();
                   // map = mapFragment.getMap();
                    // Set the map center to the Vancouver region (no animation)
                    //map.setCenter(new GeoCoordinate(15.1447, 120.5957, 0.0), Map.Animation.NONE);
                    // Set the zoom level to the average between min and max
                    //map.setZoomLevel(
                           // (map.getMaxZoomLevel() + map.getMinZoomLevel()) / 2);
                } else {
                    System.out.println("ERROR: Cannot initialize Map Fragment");
                }
            }
        });

    }
    private void onMapFragmentInitializationCompleted() {
        // retrieve a reference of the map from the map fragment
        map = mapFragment.getMap();
        // Set the map center coordinate to the Vancouver region (no animation)
        map.setCenter(new GeoCoordinate(49.196261, -123.004773, 0.0),
                Map.Animation.NONE);
        // Set the map zoom level to the average between min and max (no
        // animation)
        map.setZoomLevel((map.getMaxZoomLevel() + map.getMinZoomLevel()) / 2);
    }


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

}
 <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />

    <!-- Map Fragment embedded with the map object -->
    <fragment
        class="com.here.android.mpa.mapping.MapFragment"
        android:id="@+id/mapfragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>


我认为您没有添加所需的所有权限,请查看下图

我知道答案已经很晚了。但我一直在寻找解决同样问题的办法。也许它会帮助别人

Map Service是一种Android服务,可在使用HERE SDK的应用程序之间方便地使用共享磁盘缓存。此服务必须嵌入并与启用此功能的应用程序一起部署;否则,将通过
onEngineInitializationCompleted()
回调返回缺少\u服务的错误代码

要嵌入地图服务,请在您的
AndroidManifest.xml文件

<service
android:name="com.here.android.mpa.service.MapService"
android:label="HereMapService"
android:process="global.Here.Map.Service.v2"
android:exported="true" >
<intent-filter>
<action android:name="com.here.android.mpa.service.MapService" >
</action>
</intent-filter>
</service>


请添加设备的
logcat
屏幕截图
,并正确检查。感谢您的回答。我想问题在于这些设备。因为在通用Elite设备上尝试run应用程序之前,地图没有显示。然后,尝试在三星GT-N5110设备上运行,并显示地图。但我找不到原因,你知道吗?