Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么我会得到NullPointerException?_Java_Android_Nullpointerexception - Fatal编程技术网

Java 为什么我会得到NullPointerException?

Java 为什么我会得到NullPointerException?,java,android,nullpointerexception,Java,Android,Nullpointerexception,当我指向某个存在的东西时,为什么会出现NullPointerException View header = (View)inflater.inflate(R.layout.listview_header_row, null); 类别代码 public class FeaturedDealsFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup con

当我指向某个存在的东西时,为什么会出现NullPointerException

View header = (View)inflater.inflate(R.layout.listview_header_row, null);
类别代码

public class FeaturedDealsFragment extends Fragment {

@Override  
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {  

    View V = inflater.inflate(R.layout.fragment_featured_deals, container, false);
    ListView LV = (ListView) this.getActivity().findViewById(R.id.dealsListView);

    Deal deal_data[] = new Deal[]
            {
                new Deal("Deal 1", R.drawable.scenery, "500/100 Supporters", "$500"),
                new Deal("Deal 2", R.drawable.scenery, "500/100 Supporters", "$500"),
                new Deal("Deal 3", R.drawable.scenery, "500/100 Supporters", "$500"),
                new Deal("Deal 4", R.drawable.scenery, "500/100 Supporters", "$500"),
                new Deal("Deal 5", R.drawable.scenery, "500/100 Supporters", "$500")
            };

    DealAdapter adapter = new DealAdapter(getActivity(), R.layout.listview_item_row, deal_data);

    View header = (View)inflater.inflate(R.layout.listview_header_row, null);

    LV.addHeaderView(header);
    LV.setAdapter(adapter);

    return V;

}

}
列表视图\标题\行XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"> 

<TextView android:id="@+id/txtHeader"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:background="#ffffff"
    style="@style/fragment_main_heading"
    android:textColor="#000000"
    android:text="@string/featuredDeals" />

</LinearLayout>
试试这个

ListView LV = (ListView) V.findViewById(R.id.dealsListView);
而不是这个

ListView LV = (ListView) this.getActivity().findViewById(R.id.dealsListView);
因为
V
父视图,所以您需要使用此..

尝试此

ListView LV = (ListView) V.findViewById(R.id.dealsListView);
而不是这个

ListView LV = (ListView) this.getActivity().findViewById(R.id.dealsListView);

因为
V
父视图,所以您需要使用此..

请发布日志cat输出。添加了我的日志cat。有点长-请发布日志猫输出。添加了我的日志猫。有点长-非常感谢!这解决了我所有的努力。在这件事上扯了我一段时间的头发!完成!我在等柜台倒下来。我把功劳归于应得的地方=]非常感谢!这解决了我所有的努力。在这件事上扯了我一段时间的头发!完成!我在等柜台倒下来。我在信用到期时给予信用=]