android.content.res.Resources $ NotFoundException:资源ID#0x7f020278

时间:2015-07-14 02:54:51

标签: java android google-maps

我是Android编程的新手,我正在尝试使用当前位置的地图,但是当我查看logcat时,我看到以下错误:

  

RunTimeException android.content.res.Resources $ NotFoundException:   资源ID#0x7f020278 at   android.content.res.Resources.getValue(Resources.java:2329)at   android.content.res.Resources.startRC(Resources.java:1057)at   android.app.ActivityThread $ mRunnable.run(ActivityThread.java:2477)at at   java.lang.Thread.run(Thread.java:818)07-15 18:40:16.624 13526-13526   com.example.paul.mapasxavo E / ViewRootImpl:sendUserActionEvent()mView   == null

MapsActiviy类中的Java代码是:

public class MapsActivity extends FragmentActivity {
    // Might be null if Google Play services APK is not available.
    private GoogleMap mMap; 
    private SensorManager sensorManager;
    private Sensor accelerometer;
    LocationManager locationManager;

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

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }

    private void setUpMap() {
        LOCATION_SERVICE locationManager = 
            (LocationManager)getSystemService(LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        String provider = locationManager.getBestProvider(criteria, true);
        Location location = locationManager.getLastKnownLocation(provider);
        mMap.clear();
        LatLng currentPosition = new LatLng(location.getLatitude(), location.getLongitude());
        mMap.addMarker(new MarkerOptions().position(currentPosition).title("Yo"));

        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentPosition, 13));
        mMap.setMyLocationEnabled(true);
        Log.v("MapaActivity", currentPosition.toString());
    }
}

这是XML文件

<fragment 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:id="@+id/map"
    tools:context="com.example.paul.mapasxavo.MapsActivity"
    android:name="com.google.android.gms.maps.SupportMapFragment" />

我做错了什么?

2 个答案:

答案 0 :(得分:0)

我通过这种简单的方法解决了同样的错误。检查XML布局是否为 abc.xml(xlarge-mdpi),然后只需删除它并在默认布局文件夹中创建新的abc.xml 。确保它不应该像以前那样。

答案 1 :(得分:0)

从drawable-v24中删除图像并将其放置在drawable中,因为它们仅支持API 24以上。