0
public class BabyNamesActivity extends ListActivity {
public ArrayList<HashMap<String, String>> List1, List2, List3;
public ListView lv;
public BabyNamesActivity bnaInstance = null;
this.getListView().setOnScrollListener(new OnScrollListener(){
//useless here, skip!
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
//dumdumdum
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if(firstVisibleItem + visibleItemCount == totalItemCount)
{
bnaInstance.fillListNew(10); //NOT WORKING HERE
}
}
});
fillList(1); // WORKING HERE
fillListNew(10); // WORKING HERE
}
public void fillList (int RecordNo)
{
List1=myFun(RecordNo);
ListAdapter adapter = new SimpleAdapter(this, List1 , R.layout.main,
new String[] { "name", "meaning", "gender" },
new int[] { R.id.item_babyname, R.id.item_meaning, R.id.item_gender });
lv = getListView();
lv.setAdapter(adapter);
};
public ArrayList<HashMap<String, String>> myFun (int Start)
{
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
JSONObject json = JSONfunctions.getJSONfromURL("http://localhost/Andriod/babynames.php".concat("?start=").concat(Integer.toString(Start)));
try{
JSONArray babynames = json.getJSONArray("babynames");
for(int i=0;i<babynames.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = babynames.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("name", "" + e.getString("babyName"));
map.put("meaning", e.getString("meaning"));
map.put("gender", e.getString("gender"));
mylist.add(map);
}
}catch(JSONException e) {
Toast.makeText(BabyNamesActivity.this, e.toString() , Toast.LENGTH_LONG).show();
Log.e("log_tag", "Error parsing data "+e.toString());
}
return mylist;
};
你是否在logcat中出現錯誤? – kosa 2012-01-16 01:07:44
應用程序在強制關閉時出現錯誤日誌 - 01-16 00:44:28.726:E/AndroidRuntime(232):未捕獲的處理程序:由於未捕獲的異常導致主線程退出 01-16 00:44:28.736:E/AndroidRuntime (232):java.lang.RuntimeException:無法啓動活動ComponentInfo {com.gotit.babynames/com.got.babynames.BabyNamesActivity}:java.lang.NullPointerException – Rajesh 2012-01-16 01:29:07
我認爲你不需要binstance.filllist ....,只是fillList ...應該夠了。試一下。 – kosa 2012-01-16 02:03:31