我有一个列表视图,通过键“hubahuba”从不同活动的编辑文本接收用户输入。当我点击包含此.class的水龙头时,我收到基于logcat的NullPointerException错误,我知道它与我的“String trackinput”行有关,请帮助任何人????
public static ArrayList<String> list = new ArrayList<String>();
public static ArrayAdapter<String> adapter;
LisstView lv;
String trackinput;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_argue_list);
//listViewCode
ListView lv = (ListView)findViewById(android.R.id.list);
//Intent to receive from other activity
Intent i = getIntent();
String trackinput = i.getExtras().getString("hubahuba");
//basic adapter
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
lv.setAdapter(adapter);
list.add(0, trackinput);
adapter.notifyDataSetChanged();
setListAdapter(adapter);
}
这是从活动1转到活动2中的listView:
public void onClick(View v) {
Intent i = new Intent(this, ArgueListActivity.class);
i.putExtra("hubahuba",whatedit.getText().toString());
whatedit.setText("");
}
答案 0 :(得分:0)
您不必创建Intent
你可以这样做:
String trackinput = getIntent().getStringExtra("hubahuba");
同样Collin指出
LisstView lv;
和
ListView lv = (ListView)findViewById(android.R.id.list);
含糊不清
<小时/> 将数据放入intent后,您必须启动活动,并将其传递给intent 它。
public void onClick(View v) {
Intent i = new Intent(this, ArgueListActivity.class);
i.putExtra("hubahuba",whatedit.getText().toString());
whatedit.setText("");
startActivity(i)
}