当我使用这个XML文件时。我的Java Code Code工作正常。
<?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>
当我开始使用这个XML文件时,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:apiKey="0s_fADEBtq0-j_teQ1j-yaoDAivoHHtwN81rJ-g"
android:clickable="true"
android:state_enabled="true" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<ListView
android:id="@+id/listView1"
android:layout_width="164dp"
android:layout_height="142dp"
android:layout_weight="0.33" >
</ListView>
</LinearLayout>
</LinearLayout>
因此,在Android屏幕的上半部分,我可以显示Google Map
,在下半部分,我可以显示带有图像的ListView。但每当我使用这个XML文件时,它就会开始给我一个例外 -
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.weatheractivity/com.example.weatheractivity.MainActivity}: java.lang.ClassNotFoundException: com.example.weatheractivity.MainActivity
以下是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;
}
}
答案 0 :(得分:2)
由于地图库不是标准Android库的一部分,因此您必须在Android Manifest中声明它。打开AndroidManifest.xml文件,并将以下内容添加为元素的子元素:
<uses-library android:name="com.google.android.maps"/>
https://developers.google.com/maps/documentation/android/hello-mapview