gpt4 book ai didi

java - 无法实例化 Activity ComponentInfo Android 错误

转载 作者:行者123 更新时间:2023-11-29 22:00:37 27 4
gpt4 key购买 nike

<分区>

当我使用这个 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>

当我开始使用这个 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;
}
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com