NullPointerException异常误差ArrayAdapter和ListView [英] NullPointerException Error for ArrayAdapter and ListView
问题描述
我有通过钥匙hubahuba收到来自编辑的文本在不同的活动用户输入的列表视图。当我点击包含此的.class我收到的基础上,我知道它与我的字符串trackinput行做的logcat的NullPointerException异常错误水龙头请任何帮助球员?
公共静态的ArrayList<串GT;名单=新的ArrayList<串GT;();
公共静态ArrayAdapter<串GT;适配器;LisstView LV;
串trackinput;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_argue_list); // ListView控件code LV的ListView =(ListView控件)findViewById(android.R.id.list); //意图从其他活动接收 意向I = getIntent(); 串trackinput = i.getExtras()的getString(hubahuba); //基本适配器 适配器=新ArrayAdapter<串GT;(这一点,android.R.layout.simple_list_item_1,清单);
lv.setAdapter(适配器);
list.add(0,trackinput);
adapter.notifyDataSetChanged();
setListAdapter(适配器);}
这是从活动一去到ListView在活动2:
公共无效的onClick(视图v){
意图I =新意图(这一点,ArgueListActivity.class);
i.putExtra(hubahuba,whatedit.getText()的toString());
whatedit.setText();
}
您不必创建一个新的实例意图
您可以做这样的:
字符串trackinput = getIntent()getStringExtra(hubahuba);
另外,作为科林指出
LisstView LV;
和
的ListView LV =(ListView控件)findViewById(android.R.id.list);
暧昧
你投入的意图数据后,你必须启动活动,并把它传递的意图
吧。
公共无效的onClick(视图v){
意图I =新意图(这一点,ArgueListActivity.class);
i.putExtra(hubahuba,whatedit.getText()的toString());
whatedit.setText();
startActivity㈠
}
I have a listview that receives user input from edit text in a different activity via key "hubahuba". When I click on the tap that contains this .class I receive the NullPointerException Error based on the logcat I know it has to do with my "String trackinput" Line PLEASE any help guys???
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);
}
This is from activity 1 going to the listView in Activity 2:
public void onClick(View v) {
Intent i = new Intent(this, ArgueListActivity.class);
i.putExtra("hubahuba",whatedit.getText().toString());
whatedit.setText("");
}
You don't have to create a new instance of Intent
You can just do it like this:
String trackinput = getIntent().getStringExtra("hubahuba");
Also as Collin pointed out
LisstView lv;
and
ListView lv = (ListView)findViewById(android.R.id.list);
are ambiguous
After you put data into the intent you have to start the activity, and pass it the intent to it.
public void onClick(View v) {
Intent i = new Intent(this, ArgueListActivity.class);
i.putExtra("hubahuba",whatedit.getText().toString());
whatedit.setText("");
startActivity(i)
}
这篇关于NullPointerException异常误差ArrayAdapter和ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!