Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

android - The source attachment does not contain the source for the file Layoutinflater.class

I'm trying to write an android application that uses google maps api version 2.
In Debug the application crashes when it executes the instruction:

        setContentView(R.layout.activity_poi_map);

This is the error:

the source attachment does not contain the source for the file Layoutinflater.class

I don't understand the reason. In headers I imported the whole class

android.view.*

Thank you in advance for any answer.

This is the code:

public class PoiMap extends FragmentActivity {

    private GoogleMap pMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent callerIntent = getIntent();
        final LatLng userCoord = callerIntent.getParcelableExtra("userCoord");
        final Poi poi = (Poi) callerIntent.getSerializableExtra("poi");

        setContentView(R.layout.activity_poi_map);
        setUpMapIfNeeded(userCoord);

        // Sets a callback that's invoked when the camera changes.
        pMap.setOnCameraChangeListener(new OnCameraChangeListener() {

            @Override
            /* Only use the simpler method newLatLngBounds(boundary, padding) to generate 
             * a CameraUpdate if it is going to be used to move the camera *after* the map 
             * has undergone layout. During layout, the API calculates the display boundaries 
             * of the map which are needed to correctly project the bounding box. 
             * In comparison, you can use the CameraUpdate returned by the more complex method 
             * newLatLngBounds(boundary, width, height, padding) at any time, even before the 
             * map has undergone layout, because the API calculates the display boundaries 
             * from the arguments that you pass. 
             * @see com.google.android.gms.maps.GoogleMap.OnCameraChangeListener#onCameraChange(com.google.android.gms.maps.model.CameraPosition)
             */
            public void onCameraChange(CameraPosition arg0) {
                // Move camera.
                if (poi != null){
                    LatLng poiCoord = poi.getLatLng();
                    pMap.addMarker(new MarkerOptions()
                    .position(poiCoord)
                    .title(poi.getName())
                    .snippet(poi.getCategory())
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_star)));

                    Log.d("userCoord", userCoord.toString());
                    Log.d("poiCoord", poiCoord.toString());

                    double minY = Math.min(userCoord.latitude, poiCoord.latitude);
                    double minX = Math.min(userCoord.longitude, poiCoord.longitude);
                    double maxY = Math.max(userCoord.latitude, poiCoord.latitude);
                    double maxX = Math.max(userCoord.longitude, poiCoord.longitude);

                    Log.d("minY", " " + minY);
                    Log.d("minX", " " + minX);
                    Log.d("maxY", " " + maxY);
                    Log.d("maxX", " " + maxX);

                    LatLng northEast = new LatLng(maxY, maxX);
                    LatLng southWest = new LatLng(minY, minX);
                    LatLngBounds bounds = new LatLngBounds(southWest, northEast);

                    // move camera
                    pMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 40));

                    // Remove listener to prevent position reset on camera move.
                    pMap.setOnCameraChangeListener(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.activity_poi_map, menu);
        return true;
    }

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded(new LatLng(0.0, 0.0));
    }

    private void setUpMapIfNeeded(LatLng coord) {
        // Do a null check to confirm that we have not already instantiated the map.
        if (pMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            pMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            if (pMap != null) {
                setUpMap(coord);
            }
        }
    }

    private void setUpMap(LatLng userCoord) {
        pMap.addMarker(new MarkerOptions()
                            .position(userCoord)
                            .title("Your location")
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_user)));
        pMap.animateCamera(CameraUpdateFactory.newLatLng(userCoord));

        /* public static CameraUpdate newLatLngZoom (LatLng latLng, float zoom) 
         * Returns a CameraUpdate that moves the center of the screen to a latitude 
         * and longitude specified by a LatLng object, and moves to the given zoom 
         * level.
         * Parameters
         * latLng   a LatLng object containing the desired latitude and longitude.
         * zoom     the desired zoom level, in the range of 2.0 to 21.0. 
         * Values below this range are set to 2.0, and values above it are set to 21.0. 
         * Increase the value to zoom in. Not all areas have tiles at the largest zoom levels.
         * Returns
         * a CameraUpdate containing the transformation. 
*/
        pMap.animateCamera(CameraUpdateFactory.newLatLngZoom(userCoord, 15));

    }

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is a common question and I can never find a good answer for anyone so I'll do my best to help.

This sounds like you are missing the source code for Android. You need to download the Sources for Android SDK in Eclipse with the SDK Manager.

  1. Open the SDK Manager in Eclipse
  2. Find the version of android you want the source for. In this example, Android 4.2 (API17)
  3. Check the box Sources for Android SDK
  4. Click Install # packages

For example

enter image description here

After that, run your program and get to the point that you get that error. Now you will need to attach the documentation you've downloaded

Short

  1. Click the button Edit Source Lookup Path
  2. Click the Default folder
  3. Click Add
  4. Select File System Directory and click OK
  5. Locate your downloaded source code. In this example, look for android-17 for API17. It will be in a directory such as adt-bundlesdksourcesandroid-17
  6. Click OK a few times and your source is now linked.

Long

Click the button Edit Source Lookup Path

enter image description here

Click the Default folder and click Add

enter image description here

Select File System Directory and click OK

enter image description here

Locate your downloaded source code. In this example, look for android-17 for API17. It will be in a directory such as adt-bundlesdksourcesandroid-17

enter image description here

Click OK twice and it should look something like this

enter image description here

Click OK and enjoy your source code


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...