代码及相关xml如下:
discovery.xml:
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
DiscoveryActivity.java:
public class DiscoveryActivity extends ListActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.discovery);
}
}
在编译时不会报错,但是在运行时,adb打出来的错误为:
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.DiscoveryActivity/net.DiscoveryActivity.DiscoveryActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
解决办法:
将discovery.xml中的代码改为如下:
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
问题得到解决