1
今天我收到了一個未知的NullPointerException,我無法再現它。 Logcat顯示它不是由於我的代碼而發生的。 由於在ListView中發生了異常,我的問題是,因爲它沒有指向我的代碼,因爲它發生了。 我是新到Android 這裏的logcat的:Android中的未知NullPointerException
02-07 18:32:46.796: D/AndroidRuntime(20239): Shutting down VM
02-07 18:32:46.796: W/dalvikvm(20239): threadid=1: thread exiting with uncaught exception (group=0x412ec2a0)
02-07 18:32:46.806: E/AndroidRuntime(20239): FATAL EXCEPTION: main
02-07 18:32:46.806: E/AndroidRuntime(20239): java.lang.NullPointerException
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.AbsListView.obtainView(AbsListView.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.ListView.makeAndAddView(ListView.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.ListView.fillDown(ListView.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.ListView.fillSpecific(ListView.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.ListView.layoutChildren(ListView.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.AbsListView.onLayout(AbsListView.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.View.layout(View.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewGroup.layout(ViewGroup.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.FrameLayout.onLayout(FrameLayout.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.View.layout(View.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewGroup.layout(ViewGroup.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.FrameLayout.onLayout(FrameLayout.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.View.layout(View.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewGroup.layout(ViewGroup.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.FrameLayout.onLayout(FrameLayout.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.View.layout(View.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewGroup.layout(ViewGroup.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:690)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.View.layout(View.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewGroup.layout(ViewGroup.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.FrameLayout.onLayout(FrameLayout.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.View.layout(View.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewGroup.layout(ViewGroup.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.FrameLayout.onLayout(FrameLayout.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.View.layout(View.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewGroup.layout(ViewGroup.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.LinearLayout.setChildFrame(LinearLayout.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.LinearLayout.onLayout(LinearLayout.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.View.layout(View.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewGroup.layout(ViewGroup.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.LinearLayout.setChildFrame(LinearLayout.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.LinearLayout.layoutVertical(LinearLayout.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.LinearLayout.onLayout(LinearLayout.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.View.layout(View.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewGroup.layout(ViewGroup.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.FrameLayout.onLayout(FrameLayout.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.View.layout(View.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewGroup.layout(ViewGroup.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.widget.FrameLayout.onLayout(FrameLayout.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.View.layout(View.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewGroup.layout(ViewGroup.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.Choreographer$CallbackRecord.run(Choreographer.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.Choreographer.doCallbacks(Choreographer.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.Choreographer.doFrame(Choreographer.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.os.Handler.handleCallback(Handler.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.os.Handler.dispatchMessage(Handler.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.os.Looper.loop(Looper.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at android.app.ActivityThread.main(ActivityThread.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at java.lang.reflect.Method.invokeNative(Native Method)
02-07 18:32:46.806: E/AndroidRuntime(20239): at java.lang.reflect.Method.invoke(Method.java:511)
02-07 18:32:46.806: E/AndroidRuntime(20239): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
02-07 18:32:46.806: E/AndroidRuntime(20239): at dalvik.system.NativeStart.main(Native Method)
任何幫助,將不勝感激。
好吧,這是我的適配器
的代碼private class FileAdapter extends BaseAdapter {
private final Context mContext;
private final Bitmap mFolderBitmap, mFileBitmap;
FileAdapter(Context context) {
mContext = context;
addHeader();
mFolderBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_folder);
mFileBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_file);
}
public void addHeader() {
// add empty view with height of ActionBar
View view = new View(mContext);
view.setLayoutParams(new AbsListView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
MainActivity.ACTIONBAR_HEIGHT));
getListView().addHeaderView(view);
}
@Override
public int getCount() {
return mFileList.size();
}
@Override
public Object getItem(int position) {
return mFileList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
multiChoiceListener.refresh();
}
public void setChecked(View view) {
if (view != null) {
view.setBackgroundColor(getResources().getColor(R.color.BLUE));
}
}
public void setUnchecked(View view) {
if (view != null) {
view.setBackgroundColor(getResources().getColor(R.color.WHITE));
}
}
public void setChecked(int pos) {
View view = getChildAt(getListView(), pos);
setChecked(view);
}
public void setUnchecked(int pos) {
View view = getChildAt(getListView(), pos);
setUnchecked(view);
}
private View getChildAt(AbsListView listView, Integer position) {
return listView.getChildAt(position + 1
- listView.getFirstVisiblePosition());
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
final ViewHolder vh;
if (convertView == null) {
vh = new ViewHolder();
convertView = LayoutInflater.from(mContext).inflate(
R.layout.file_fragment_list_item, parent, false);
vh.iv = (ImageView) convertView.findViewById(R.id.fileIconView);
vh.tv = (TextView) convertView.findViewById(R.id.fileTextView);
convertView.setTag(vh);
} else {
vh = (ViewHolder) convertView.getTag();
}
vh.iv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
multiChoiceListener.selectionChanged(position);
}
});
if (multiChoiceListener.isChecked(position)) {
setChecked(convertView);
} else {
setUnchecked(convertView);
}
final File file = mFileList.get(position);
if (file == null)
return null;
if (file.isDirectory()) {
vh.iv.setImageBitmap(mFolderBitmap);
} else {
vh.iv.setImageBitmap(mFileBitmap);
}
// Set text
vh.tv.setText(file.getName());
return convertView;
}
private class ViewHolder {
ImageView iv;
TextView tv;
}
}
顯示您的代碼.. – Ranjit
沒有任何代碼我們如何追蹤原因? –
很可能它的適配器的getView(...)方法失敗。 –