2013-02-18 150 views
2

我想要编写使用谷歌地图API版本2
在调试应用程序崩溃的Android应用程序,当执行该指令:源附件不包含该文件Layoutinflater.class

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

    } 

} 
+3

这不是应用程序崩溃的原因,读取红色LogCat行堆栈跟踪。您所看到的仅仅意味着您没有将您的项目链接到Android源代码(这不需要编写应用程序)。 – Sam 2013-02-18 18:34:36

回答

2

这是一个常见的问题,我无法找到任何人,所以我会尽我所能来帮助一个很好的答案。

这听起来像你缺少Android的源代码。您需要在Eclipse中下载Android SDK的源代码,SDK管理器

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

例如

enter image description here

后那么,运行你的程序,并得到你的错误。现在,您将需要连接你下载

文档短

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

点击按钮编辑源查找路径

enter image description here

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

enter image description here

选择文件系统目录并单击OK

enter image description here

找到您下载的源代码。在此示例中,查找API17的android-17。这将是一个目录,如adt-bundle\sdk\sources\android-17

enter image description here

点击OK两次,它应该是这个样子

enter image description here

点击OK,享受你的源代码

0

这通常意味着您无法访问源代码的字节码正在被调用。为了列出异常,你需要原始的源代码,不幸的是它通常在jar格式中不可用。

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