源附件不包含文件Layoutinflater.class的源

时间:2013-02-18 18:21:36

标签: android

我正在尝试编写一个使用谷歌地图api版本2的Android应用程序 在Debug中,应用程序在执行指令时崩溃:

        setContentView(R.layout.activity_poi_map);

这是错误:

  

源附件不包含文件的来源   Layoutinflater.class

我不明白原因。在标题中我导入了整个类

android.view.*

提前感谢您的回答。

这是代码:

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));

    }

}

2 个答案:

答案 0 :(得分:2)

这是一个常见的问题,我永远找不到任何人的好答案,所以我会尽力帮助。

这听起来像是你缺少Android的源代码。您需要使用 SDK Manager 在Eclipse中下载 Android SDK的源代码

  1. 在Eclipse中打开 SDK Manager
  2. 找到您想要源的Android版本。在此示例中, Android 4.2(API17)
  3. 选中 Android SDK来源
  4. 点击安装#包
  5. 例如

    enter image description here

    之后,运行您的程序,直到您收到该错误。现在您需要附上您下载的文档

    <强>短

    1. 点击按钮编辑源查找路径
    2. 点击默认文件夹
    3. 点击添加
    4. 选择文件系统目录,然后点击确定
    5. 找到下载的源代码。在此示例中,为API17查找 android-17 。它将位于adt-bundle\sdk\sources\android-17
    6. 等目录中
    7. 点击“确定”几次,您的来源现已关联。
    8. <强>长

      点击按钮编辑源查找路径

      enter image description here

      点击默认文件夹,然后点击添加

      enter image description here

      选择文件系统目录,然后点击确定

      enter image description here

      找到下载的源代码。在此示例中,为API17查找 android-17 。它将位于adt-bundle\sdk\sources\android-17

      等目录中

      enter image description here

      点击确定两次,它应该看起来像这样

      enter image description here

      点击确定并享受您的源代码

答案 1 :(得分:0)

这通常意味着您无法访问正在调用其字节码的源代码。为了列出异常,您需要原始来源,遗憾的是,这种来源通常不会以jar格式提供。

您的选择是通过使用正确的Rev更新您的Android SDK来更新.jar文件,并让它再次编译以解决问题。