应用程序没有响应。使用ListActivity

时间:2016-11-17 21:01:10

标签: android android-layout listview android-studio android-activity

当我尝试启动应用程序时,它会在显示某些内容之前关闭。我使用ListActivity,我使用这个站点编写代码:Android ListActivity Example。我认为代码中的一切都很好。那可能是什么?

public class MainActivity extends ListActivity {

static int kiekis, n = 10000, s = 20000, f = 30000, p1 = 40000, p2 = 50000, pozicija, i = 1;
ArrayList<String> list;
static String vardas;
static String numeris;
static String skype;
static String facebook;
static String papildoma1;
static String papildoma2;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SharedPreferences sprefs = getSharedPreferences("Prefs", MODE_PRIVATE);
    list = new ArrayList<String>();
    for (i = 1; i <= kiekis; i++) {
        vardas = sprefs.getString(String.valueOf(i), "");
        list.add(vardas);
    }
    setListAdapter(new ArrayAdapter<String>(this,
            R.layout.list_view, R.id.vardas, list));
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    //String item = (String) getListAdapter().getItem(position);
    Intent intent = new Intent(MainActivity.this, Detail.class);

    pozicija = position;

    SharedPreferences sprefs = getPreferences(MODE_PRIVATE);
    numeris = sprefs.getString(String.valueOf(n + position), "");
    skype = sprefs.getString(String.valueOf(s + position), "");
    facebook = sprefs.getString(String.valueOf(f + position), "");
    papildoma1 = sprefs.getString(String.valueOf(p1 + position), "");
    papildoma2 = sprefs.getString(String.valueOf(p2 + position), "");

    startActivity(intent);
    finish();
}

}

1 个答案:

答案 0 :(得分:0)

尝试在第一行放置断点并在调试模式下运行。然后你可以看到它破坏的地方