ONCREATE I PUT
ListView listView = (ListView) findViewById(R.id.listView3);
以下是我的listview获取空指针崩溃应用程序的代码由于某种原因我的listview从下面的代码找不到请告诉我在做什么
@Override
protected void onPostExecute(Void result) {
parsedHtmlNode.setText(htmlContentInStringFormat);
String input = amarrdatta;
String dayyz = dayys;
dayyz = dayyz.replace(" ", System.getProperty("line.separator"));
input = input.replace(" ", System.getProperty("line.separator"));
// textViewwww.setText(dayyz +" " +input);
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
count++;
temp=temp+count;
HashMap<String,String> temp=new HashMap<String, String>();
temp.put(FIRST_COLUMN, dayyz);
temp.put(SECOND_COLUMN, input);
temp.put(THIRD_COLUMN, "22");
temp.put(FOURTH_COLUMN, "Unmarried");
list.add(temp);
ListViewAdapter adapter=new ListViewAdapter(MainActivity.this, list);
listView.setAdapter(adapter); // getting nullpointer here listview
}
}
java null指针仍然是
@Override
protected void onPostExecute(Void result) {
parsedHtmlNode.setText(htmlContentInStringFormat);
String input = amarrdatta;
String dayyz = dayys;
dayyz = dayyz.replace(" ", System.getProperty("line.separator"));
input = input.replace(" ", System.getProperty("line.separator"));
// textViewwww.setText(dayyz +" " +input);
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
count++;
temp=temp+count;
HashMap<String,String> temp=new HashMap<String, String>();
temp.put(FIRST_COLUMN, dayyz);
temp.put(SECOND_COLUMN, input);
temp.put(THIRD_COLUMN, "22");
temp.put(FOURTH_COLUMN, "Unmarried");
list.add(temp);
ListViewAdapter adapter=new ListViewAdapter(MainActivity.this, list);
ListView listView = (ListView) findViewById(R.id.listView3);
listView.setAdapter(adapter);
}
答案 0 :(得分:0)
您未初始化listView
变量。
您在ListView listView = (ListView) findViewById(R.id.listView3);
中onCreate()
。但是,使用此代码重新声明listView
变量,它隐藏全局listView
,全局listView
保持为空。
删除onCreate()
中的类型:
listView = (ListView) findViewById(R.id.listView3);
或将完整行移至onPostExecute()
。
答案 1 :(得分:0)
尝试将ListView listView;
移到onCreate:
ListView listView;
protected void onCreate(Bundle savedInstanceState) {
listView = (ListView) findViewById(R.id.listView3);
}
@Override
protected void onPostExecute(Void result) {
parsedHtmlNode.setText(htmlContentInStringFormat);
String input = amarrdatta;
String dayyz = dayys;
dayyz = dayyz.replace(" ", System.getProperty("line.separator"));
input = input.replace(" ", System.getProperty("line.separator"));
// textViewwww.setText(dayyz +" " +input);
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
count++;
temp=temp+count;
HashMap<String,String> temp=new HashMap<String, String>();
temp.put(FIRST_COLUMN, dayyz);
temp.put(SECOND_COLUMN, input);
temp.put(THIRD_COLUMN, "22");
temp.put(FOURTH_COLUMN, "Unmarried");
list.add(temp);
ListViewAdapter adapter=new ListViewAdapter(MainActivity.this, list);
listView.setAdapter(adapter); // getting nullpointer here listview
}
答案 2 :(得分:0)
正确检查您的XML ListView
ID,然后您需要使用如下
片段或其他布局膨胀
View view = inflater.inflate(R.layout.layoutname, container, false);
ListView listView = (ListView) view.findViewById(R.id.listView3);
<强>活动强>
ListView listView = (ListView) findViewById(R.id.listView3);
答案 3 :(得分:0)
我猜你没有把你的AsyncTask放在你的Activity类中。确保你的AsyncTask是你Activity的内部类