-2
我正在試圖做一個無限的滾動像Twitter,我使用Android的無限滾動列表視圖,但始終出現此錯誤。致命的例外:AsyncTask#1進程
FATAL EXCEPTION: AsyncTask #1
Process: candel.ramon.cloudy, PID: 14907
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NullPointerException
at candel.ramon.cloudy.TablonCloudy$1$1.doInBackground(TablonCloudy.java:75)
這是我的課:
public class TablonCloudy extends Activity {
// A setting for how many items should be loaded at once from the server
private static final int SEVER_SIDE_BATCH_SIZE = 10;
private InfiniteScrollListView infiniteScroll;
private TablonAdapter tablonAdapter;
// cambiar nombre y datos de esta clase
private BogusRemoteService bogusRemoteService;
private Handler handler;
private AsyncTask<Void, Void, List<String>> fetchAsyncTask;
private Map<String, Integer> sushiMappings;
// formas de cargar
private LoadingMode loadingMode = LoadingMode.SCROLL_TO_TOP;
private StopPosition stopPosition = StopPosition.START_OF_LIST;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tablon_cloudy);
handler = new Handler();
infiniteScroll = (InfiniteScrollListView) this
.findViewById(R.id.infinite_scrollview);
infiniteScroll.setLoadingMode(loadingMode);
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
infiniteScroll.setLoadingView(layoutInflater.inflate(
R.layout.loading_view, null));
tablonAdapter = new TablonAdapter(new NewPageListener() {
@Override
public void onScrollNext() {
fetchAsyncTask = new AsyncTask<Void, Void, List<String>>() {
@Override
protected void onPreExecute() {
// Loading lock to allow only one instance of loading
tablonAdapter.lock();
}
@Override
protected List<String> doInBackground(Void... params) {
List<String> result;
// Mimic loading data from a remote service
if (loadingMode == LoadingMode.SCROLL_TO_TOP) {
result = bogusRemoteService
.getNextMessageBatch(SEVER_SIDE_BATCH_SIZE);
} else {
result = bogusRemoteService
.getNextSushiBatch(SEVER_SIDE_BATCH_SIZE);
}
return result;
}
@Override
protected void onPostExecute(List<String> result) {
if (isCancelled() || result == null || result.isEmpty()) {
tablonAdapter.notifyEndOfList();
} else {
// Add data to the placeholder
if (loadingMode == LoadingMode.SCROLL_TO_TOP) {
tablonAdapter.addEntriesToTop(result);
}
// Add or remove the loading view depend on if there
// might be more to load
if (result.size() < SEVER_SIDE_BATCH_SIZE) {
tablonAdapter.notifyEndOfList();
} else {
tablonAdapter.notifyHasMore();
}
// Get the focus to the specified position when
// loading completes
if (loadingMode == LoadingMode.SCROLL_TO_TOP) {
infiniteScroll
.setSelection(result.size() < SEVER_SIDE_BATCH_SIZE ? 0
: 1);
}
}
};
@Override
protected void onCancelled() {
// Tell the adapter it is end of the list when task is
// cancelled
tablonAdapter.notifyEndOfList();
}
}.execute();
}
@Override
public View getInfiniteScrollListView(int position,
View convertView, ViewGroup parent) {
// Customize the row for list view
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.row_demo,
null);
}
String name = (String) tablonAdapter.getItem(position);
if (name != null) {
TextView rowName = (TextView) convertView
.findViewById(R.id.row_name);
ImageView rowPhoto = (ImageView) convertView
.findViewById(R.id.row_photo);
rowName.setText(name);
if (loadingMode == LoadingMode.SCROLL_TO_TOP) {
rowPhoto.setImageResource(position % 2 == 0 ? R.drawable.conversation_driver
: R.drawable.conversation_officer);
} else {
rowPhoto.setImageResource(sushiMappings.get(name));
}
}
return convertView;
}
});
infiniteScroll.setAdapter(tablonAdapter);
// Display a toast when a list item is clicked
infiniteScroll.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
final int position, long id) {
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(
TablonCloudy.this,
tablonAdapter.getItem(position) + " "
+ getString(R.string.ordered),
Toast.LENGTH_SHORT).show();
}
});
}
});
}
任何人都知道的不喜歡Twitter或Facebook的無限滾動視圖,爲什麼會出現這個錯誤或其他圖書館?
從堆棧跟蹤,還有一個空指針異常的第75行在doInBackground –