Java 在Android项目中,单个文件有R个错误
我有一个项目可以在Eclipse中的Windows上完美地工作。由于我的大部分工作现在都是在Mac上进行的,所以我将切换到Eclipse for Mac 我已经修复了整个项目中的所有构建路径错误,剩下的只是“this_xml_name无法解析或不是字段”,理论上在构建我的R文件时会导致错误 然而,这是我第一次遇到这个问题,它只出现在一个文件中,而不仅仅是id或布局。它发生在R.layout、R.id、R.menu和R.drawable中。整个项目中的所有其他引用都非常好,在链接文件中的每个R.引用中只发现错误 MapActivity.javaJava 在Android项目中,单个文件有R个错误,java,android,xml,eclipse,resources,Java,Android,Xml,Eclipse,Resources,我有一个项目可以在Eclipse中的Windows上完美地工作。由于我的大部分工作现在都是在Mac上进行的,所以我将切换到Eclipse for Mac 我已经修复了整个项目中的所有构建路径错误,剩下的只是“this_xml_name无法解析或不是字段”,理论上在构建我的R文件时会导致错误 然而,这是我第一次遇到这个问题,它只出现在一个文件中,而不仅仅是id或布局。它发生在R.layout、R.id、R.menu和R.drawable中。整个项目中的所有其他引用都非常好,在链接文件中的每个R.引
package com.example.android;
import java.util.Timer;
import java.util.TimerTask;
import android.R;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
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;
public class MapActivity extends FragmentActivity {
FragmentActivity activity = this;
private static final int GPS_ERRORDIALOG_REQUEST = 9001;
protected GoogleMap mMap;
String locAddr;
String locName;
Double locLongitude;
Double locLatitude;
final Handler handler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (servicesOK()) {
setContentView(R.layout.activity_map);
if (initMap()) {
Bundle extras = getIntent().getExtras();
if (extras != null) {
locAddr = extras.getString("address");
locName = extras.getString("name");
locLongitude = extras.getDouble("longitude");
locLatitude = extras.getDouble("latitude");
activity.setTitle(locName);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
handler.post(new Runnable()
{
public void run()
{
LatLng coordinates = new LatLng(locLatitude, locLongitude);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(coordinates, 14.0f));
Marker marker = mMap.addMarker(new MarkerOptions()
.position(coordinates)
.title(locName)
.snippet(locAddr)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.map_marker)));
marker.showInfoWindow();
/*mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker arg0) {
Intent intent = new Intent(MapActivity.this, DetailsActivity.class);
intent.putExtra("userkey", "MattCoker");
intent.putExtra("geolat", "29.7530");
intent.putExtra("geolong", "geozip");
intent.putExtra("clientid", "0");
intent.putExtra("siteid", "0");
startActivity(intent);
}
});*/
}
});
}
}, 3000);
} else {
Toast.makeText(activity, "Something went wrong displaying this location!", Toast.LENGTH_LONG).show();
}
}
}
else {
setContentView(R.layout.no_available_maps);
}
//Show the Up button in the action bar.
setupActionBar();
}
/**
* Set up the {@link android.app.ActionBar}.
*/
private void setupActionBar() {
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
}
public boolean servicesOK() {
int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
if (isAvailable == ConnectionResult.SUCCESS) {
return true;
}
else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, activity, GPS_ERRORDIALOG_REQUEST);
dialog.show();
}
else {
Toast.makeText(activity, "Can't connect to Google Play Services", Toast.LENGTH_SHORT).show();
}
return false;
}
private boolean initMap() {
if (mMap == null) {
SupportMapFragment mapFrag = null;
mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mMap = mapFrag.getMap();
}
return (mMap != 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.main, menu);
// Associate searchable configuration with the SearchView
/*SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));*/
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int selectedMenuItem = item.getItemId();
if (selectedMenuItem == R.id.action_settings) {
Intent settingsIntent = new Intent(activity, SettingsActivity.class);
startActivity(settingsIntent);
return true;
} else if (selectedMenuItem == R.id.send_feedback) {
Intent sendFeedback = new Intent(android.content.Intent.ACTION_SEND);
sendFeedback.setType("message/rfc822");
sendFeedback.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"usersupport@example.com"});
sendFeedback.putExtra(android.content.Intent.EXTRA_SUBJECT, "Feedback on example...");
startActivity(Intent.createChooser(sendFeedback, "Send Email"));
//TODO: Create Feedback Activity to send email
return true;
}
return false;
}
}
如果资源文件中有错误,则不会生成
R.java
。修复这些错误并清理和构建
看看你的代码
import android.R;
换成
import com.example.android.R;
删除R.java文件并再次重建项目。用import com.example.android.R替换import android.R;