我在找出从哪里开始调试的问题。
这是来自logcat的信息:

01-22 18:28:20.472: E/AndroidRuntime(10859): FATAL EXCEPTION: main
01-22 18:28:20.472: E/AndroidRuntime(10859): java.lang.NullPointerException
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.widget.AbsListView.obtainView(AbsListView.java:2275)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.widget.ListView.onMeasure(ListView.java:1156)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.View.measure(View.java:15172)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.widget.RelativeLayout.measureChild(RelativeLayout.java:602)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:415)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.View.measure(View.java:15172)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.View.measure(View.java:15172)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1447)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.View.measure(View.java:15172)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.View.measure(View.java:15172)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.View.measure(View.java:15172)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.View.measure(View.java:15172)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2435)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.View.measure(View.java:15172)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1102)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.Choreographer.doFrame(Choreographer.java:525)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.os.Handler.handleCallback(Handler.java:615)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.os.Looper.loop(Looper.java:137)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at android.app.ActivityThread.main(ActivityThread.java:4931)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at java.lang.reflect.Method.invokeNative(Native Method)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at java.lang.reflect.Method.invoke(Method.java:511)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
01-22 18:28:20.472: E/AndroidRuntime(10859):    at dalvik.system.NativeStart.main(Native Method)


如您所见,没有关于我的应用程序包或与之相关的堆栈跟踪的信息

请帮忙

我的适配器代码:

公共类MyChatGroupAdapter扩展了ArrayAdapter {

private List<Item> items;
private LayoutInflater inflater;
public static int[] LIST_TYPES = { ChatActivity.VAL_MSG_TYPE_TEXT,
        ChatActivity.VAL_MSG_TYPE_IMAGE };

// private TreeSet<Integer> mSeparatorsSet = new TreeSet<Integer>();

public MyChatGroupAdapter(Context context, LayoutInflater inflater,
        List<Item> items) {
    super(context, 0, items);
    this.items = items;
    this.inflater = inflater;
}



 @Override
public void add(Item item) {
    // TODO Auto-generated method stub
    super.add(item);
    items.add(item);
}



@Override
    public int getViewTypeCount() {
        // Get the number of items in the enum
        return LIST_TYPES.length;

    }

    @Override
    public int getItemViewType(int position) {
        // Use getViewType from the Item interface
        return items.get(position).getViewType();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // Use getView from the Item interface
        return items.get(position).getView(inflater, convertView);
    }

    public void add(TextItem item,boolean addInStart) {
        // TODO Auto-generated method stub
        if(addInStart)
        items.add(0,item);
        else
            items.add(item);

        notifyDataSetChanged();
    }

    public void add(ImageItem item,boolean addInStart) {
        // TODO Auto-generated method stub
        if(addInStart)

        items.add(0,item);
        else
            items.add(item);

        notifyDataSetChanged();


    }


这是我填充列表视图的地方:

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cur) {
    // TODO Auto-generated method stub

    try{
    if (myChatGroupAdapter == null) {
        myChatGroupAdapter = new MyChatGroupAdapter(getActivity(),
                getActivity().getLayoutInflater(),
                FragmentOneChatHistory.parseChatItemsFromCursor(cur));
        Log.w("FragmentTopFansWithWHeel", "onLoadFinished: adapter was null");
    } else {

        myChatGroupAdapter.clear();
        myChatGroupAdapter.addAll(FragmentOneChatHistory.parseChatItemsFromCursor(cur));
        Log.w("FragmentTopFansWithWHeel",
                "onLoadFinished: change adapter items");



    }


    this.handler.post(new PopulateArtistGroupListView());
    }catch(Exception e)
    {
        e.printStackTrace();

    }


}


当我尝试调试它时,执行以下代码会崩溃:
this.handler.post(new PopulateArtistGroupListView());

但我无法到达PopulateArtistGroupListView内部的断点

私有类PopulateArtistGroupListView实现了Runnable {

    @Override
    public void run() {
        ListView listRecentPlayed = (ListView) getActivity().findViewById(
                R.id.listViewArtistGroup);
        listRecentPlayed.setAdapter(myChatGroupAdapter);
        listRecentPlayed
                .setOnItemClickListener(FragmentTopFansWithWHeel.this);

    }

}

最佳答案

没有人回答,但我找到了解决方案。经过一周的调试(在很多错误的地方),我发现我的自定义getItemViewType返回-1,这是导致AbsListView中出现NullPointerException的原因

关于android - 与android.widget.AbsListView.obtainView相关的NullPointerException(AbsListView.java:2275),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21290104/

10-10 13:40