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

标签 android

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

        setContentView(R.layout.activity_poi_map);

这是错误:

the source attachment does not contain the source for the file 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));

    }

}

最佳答案

这是一个常见问题,我永远无法为任何人找到好的答案,因此我会尽力提供帮助。

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

  1. 在 Eclipse 中打开SDK 管理器
  2. 找到您想要源代码的 Android 版本。在此示例中,Android 4.2 (API17)
  3. 选中Android SDK 来源复选框
  4. 点击安装 # 个软件包

例如

enter image description here

之后,运行您的程序并到达出现该错误的位置。现在您需要附上您下载的文档

简短

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

单击按钮编辑源查找路径

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

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

关于android - 源附件不包含文件 Layoutinflater.class 的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14942851/

相关文章:

android - 在 Linux 中运行 Android 应用程序

android - 单击持续通知时返回上一个 Activity

来自 Assets 目录的 Android RandomAccessFile

android - 如何解决NDK库调用卡住UI线程的问题

android - FusedLocationProviderClient 有时会给出不同的位置

android - android 设备无法接收 google play 游戏通知的可能原因?

java - 在 DialogFragment 中膨胀类 fragment 时出错

android - 在 onDoNext 和 doOnCompleted 方法中难以设置 View

android - Phonegap/Android 中的 Materialise 图标不起作用

java - View - 没有零参数构造函数