Java 无法将R解析为变量,正在尝试创建Google Maps V2项目
我正在努力学习教程 我得到一个错误,说R不能被解决。我不知道如何导入R。我想我的XML中肯定有错误,但我不确定 在这里我得到了这个错误:元素类型“useffeature”后面必须跟属性规范“>”或“/>” 我用粗体标出了我出错的地方。任何帮助都将不胜感激 我尝试过的事情:我尝试过导入R,但它一直尝试导入错误的R值。Java 无法将R解析为变量,正在尝试创建Google Maps V2项目,java,android,google-maps,maps,google-maps-api-2,Java,Android,Google Maps,Maps,Google Maps Api 2,我正在努力学习教程 我得到一个错误,说R不能被解决。我不知道如何导入R。我想我的XML中肯定有错误,但我不确定 在这里我得到了这个错误:元素类型“useffeature”后面必须跟属性规范“>”或“/>” 我用粗体标出了我出错的地方。任何帮助都将不胜感激 我尝试过的事情:我尝试过导入R,但它一直尝试导入错误的R值。 我试过清理这个项目。 编辑:加粗不适用于代码,所以没关系。这就是****所在的地方。如果有任何错误,请检查您的资源文件检查您的res文件夹是否有错误…您的清单中缺少。。但是没有生成R
我试过清理这个项目。
编辑:加粗不适用于代码,所以没关系。这就是****所在的地方。如果有任何错误,请检查您的资源文件检查您的res文件夹是否有错误…您的清单中缺少
。。但是没有生成R.java..这是因为xml文件中有一些错误您参考的教程有点旧..现在不推荐使用MapFragment..使用SupportMapFragment..检查这一点..如果您使用Eclipse,请打开问题选项卡,修复xml中显示的所有问题(与R相关的问题除外),然后干净地构建应用程序
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dublindrinkdeals"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
**<!-- Required OpenGL ES 2.0. for Maps V2 -->
<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.example.dublindrinkdeals.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>
<!-- Google Maps API Key -->
<meta-data
android:name="com.example.dublindrinkdeals.v2.API_KEY"
android:value="APIKEY" />
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
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.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends Activity {
// Google Map
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
**setContentView(R.layout.activity_main);**
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
**R.id.map)).getMap();**
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}