Java 无法实例化活动组件信息Android错误

Java 无法实例化活动组件信息Android错误,java,android,android-mapview,Java,Android,Android Mapview,当我使用这个XML文件时。我下面的Java代码运行良好 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_he

当我使用这个XML文件时。我下面的Java代码运行良好

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"> 

     <ListView
        android:id="@+id/listView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>
下面是Java代码:-

public class MainActivity extends MapActivity {

    private ListView listView1;
    private MapView mapView;
    private MapController mapController;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Weather weather_data[] = new Weather[]
                                             {
                new Weather(R.drawable.ic_launcher, "Cloudy"),
                new Weather(R.drawable.ic_launcher, "Showers"),
                new Weather(R.drawable.ic_launcher, "Snow"),
                new Weather(R.drawable.ic_launcher, "Storm"),
                new Weather(R.drawable.ic_launcher, "Sunny")
                                             };

        WeatherAdapter adapter = new WeatherAdapter(this, 
                R.layout.listview_item_row, weather_data);


        mapView = (MapView) findViewById(R.id.mapView);
        // enable Street view by default
        mapView.setStreetView(true);

        mapView.setBuiltInZoomControls(true);

        mapController = mapView.getController();
        mapController.setZoom(15);


        listView1 = (ListView)findViewById(R.id.listView1);

        View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
        listView1.addHeaderView(header);

        listView1.setAdapter(adapter);
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
    }

因为地图库不是标准Android库的一部分,所以必须在Android清单中声明它。打开AndroidManifest.xml文件并添加以下内容作为元素的子元素:

<uses-library android:name="com.google.android.maps"/>

public class MainActivity extends MapActivity {

    private ListView listView1;
    private MapView mapView;
    private MapController mapController;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Weather weather_data[] = new Weather[]
                                             {
                new Weather(R.drawable.ic_launcher, "Cloudy"),
                new Weather(R.drawable.ic_launcher, "Showers"),
                new Weather(R.drawable.ic_launcher, "Snow"),
                new Weather(R.drawable.ic_launcher, "Storm"),
                new Weather(R.drawable.ic_launcher, "Sunny")
                                             };

        WeatherAdapter adapter = new WeatherAdapter(this, 
                R.layout.listview_item_row, weather_data);


        mapView = (MapView) findViewById(R.id.mapView);
        // enable Street view by default
        mapView.setStreetView(true);

        mapView.setBuiltInZoomControls(true);

        mapController = mapView.getController();
        mapController.setZoom(15);


        listView1 = (ListView)findViewById(R.id.listView1);

        View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
        listView1.addHeaderView(header);

        listView1.setAdapter(adapter);
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
    }
<uses-library android:name="com.google.android.maps"/>