android null pointer exception setting adapter for custom list on fragment
I have a project with fragments working ok, im using actionbarsherlock,
and sliding menu by jeremyfeinstein,
all is working fine, but when I want to customize the left drawer list
cells, i get an exception
NullPointerException
here my code,
for showing the left table working fine on basic mode for list ,
simple_list_item_1
but when I customize it, I get the exception,
here the list [PhoneMenuList.java]:
public class PhoneMenuList extends SherlockListFragment{
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState){
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
//SET THE LIST ADAPTER!
Hamburger hambu_data[] = new Hamburger[]
{
new Hamburger(R.drawable.icon_hambu_folder, "My Documents"),
new Hamburger(R.drawable.icon_hambu_favs, "Top 10 viewed"),
new Hamburger(R.drawable.icon_hambu_validate, "Validate"),
new Hamburger(R.drawable.icon_hambu_how, "How to use"),
new Hamburger(R.drawable.icon_hambu_how, "About")
};
ListView productList= (ListView)
getActivity().findViewById(R.id.listView1);
//for context!
HamburgerAdapter adapter = new HamburgerAdapter(getActivity(),
R.layout.hamburger_item_row, hambu_data);
/*
View header =
(View)getLayoutInflater(savedInstanceState).inflate(R.layout.hamburger_item_row,
null);
productList.addHeaderView(header);
productList.setAdapter(adapter);
*/
}
}
on list.xml
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#000000"
android:dividerHeight="1dip" />
hamburguer item row
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<ImageView android:id="@+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView android:id="@+id/txtTitle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
</LinearLayout>
so how to fix the exception when i set my adapter
productList.setAdapter(adapter);
Thanks!
No comments:
Post a Comment