Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.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
Android R无法解析为变量(在谷歌地图上)_Android_Google Maps - Fatal编程技术网

Android R无法解析为变量(在谷歌地图上)

Android R无法解析为变量(在谷歌地图上),android,google-maps,Android,Google Maps,我知道这听起来很愚蠢,因为我问了很多人以前已经问过的问题,但我现在感到沮丧,因为我考虑的每个关于这些错误的答案(比我想提及的时间还要多)都不能使我的代码正确。 我在youtube上观看了代码制作并下载了 无论如何,这是我的示例代码 package com.example.googlemapsdemo; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.v

我知道这听起来很愚蠢,因为我问了很多人以前已经问过的问题,但我现在感到沮丧,因为我考虑的每个关于这些错误的答案(比我想提及的时间还要多)都不能使我的代码正确。 我在youtube上观看了代码制作并下载了

无论如何,这是我的示例代码

package com.example.googlemapsdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;

import com.google.android.gms.maps.CameraUpdate;
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.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends Activity {
private final LatLng LOCATION_PALEMBANG = new LatLng(-2.938201, 104.6892742);
private final LatLng LOCATION_JOHOR = new LatLng(1.5618762, 103.6365218);

private GoogleMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);    <-----this line (R cannot be   resolved to a variable)

    map  = ((MapFragment)   getFragmentManager().findFragmentById(R.id.map)).getMap(); <-----this line (R cannot be resolved to a variable)

    map.addMarker(new MarkerOptions().position(LOCATION_PALEMBANG).title("Find me here!"));
}


@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); <--- this line (same error)
    return true;
}

public void onClick_City(View v) {
   //   CameraUpdate update = CameraUpdateFactory.newLatLng(LOCATION_PALEMBANG);
    map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
    CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_PALEMBANG,     9);
    map.animateCamera(update);
}
public void onClick_Burnaby(View v) {
    map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_PALEMBANG, 14);
    map.animateCamera(update);

}
public void onClick_Surrey(View v) {
    map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    CameraUpdate update = CameraUpdateFactory.newLatLngZoom(LOCATION_JOHOR, 16);
    map.animateCamera(update);

}

}
package com.example.googlemapsdemo;
导入android.app.Activity;
导入android.os.Bundle;
导入android.view.Menu;
导入android.view.view;
导入com.google.android.gms.maps.CameraUpdate;
导入com.google.android.gms.maps.CameraUpdateFactory;
导入com.google.android.gms.maps.GoogleMap;
导入com.google.android.gms.maps.MapFragment;
导入com.google.android.gms.maps.model.LatLng;
导入com.google.android.gms.maps.model.MarkerOptions;
公共类MainActivity扩展了活动{
私人最终车床位置_PALEMBANG=新车床(-2.938201104.6892742);
私人最终LatLng位置_JOHOR=新LatLng(1.5618762103.6365218);
私人谷歌地图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

此错误通常由以下任一可能性引起:

  • 最可能的情况是:您的任何布局文件(即位于项目的res\layout文件夹下的文件)中都有语法错误。糟糕的是Eclipse不会警告您并告诉您错误在哪里,因此您必须逐个查找语法(可能是不匹配的标记、不匹配的属性等)并解决问题

  • 另一种可能是您的
    AndroidManifest.xml
    文件中存在语法错误。同样,请检查它是否存在语法错误

其中一个可以解决您的问题

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemapsdemo"
android:versionCode="1"
android:versionName="1.0" >

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

<permission
    android:name="com.example.googlemapsdemo.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>
<uses-permission android:name="com.example.googlemapsdemo.permission.MAPS_RECEIVE"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<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" >

    <uses-library
    android:name="com.example.googlemapsdemo" />

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

    <activity
        android:name="com.example.googlemapsdemo.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>
</application>
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<Button
    android:id="@+id/btnJohor"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:onClick="onClick_Johor"
    android:text="Johor" />

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_below="@+id/btnSurrey"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

<Button
    android:id="@+id/btnPalembang"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:onClick="onClick_Palembang"
    android:text="Palembang" />

<Button
    android:id="@+id/btnCity"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:onClick="onClick_City"
    android:text="City" />