iwtbbte 2015-08-27 15:24 采纳率: 22.2%
浏览 2159

写了个ListView,打开就崩溃

用的Android Studio。Activity自动在manifests里注册了。
将该activity设置为打开加载页面时,打开就直接闪退。
错误信息一闪就没了...

Java代码:
package com.demo.listview;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MyLIST extends Activity {

private String[] list=getResources().getStringArray(R.array.lesson_name_list_cn);
private ListView lv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    lv=(ListView)findViewById(R.id.lv);

    lv.setAdapter(new ArrayAdapter<>(this,
            android.R.layout.simple_list_item_1,list));
}

}

XML:
<?xml version="1.0" encoding="utf-8"?>
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.demo.listview">

<!--添加一个ListView控件-->
<ListView
    android:id="@+id/lv"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</ListView>

  • 写回答

5条回答

  • devmiao 2015-08-27 15:41
    关注

    看看是不是有没有处理的异常,特别是构造函数以及加载的逻辑

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog