Note that there are some explanatory texts on larger screens.

plurals
  1. POListview - NullPointerException at setAdapter
    primarykey
    data
    text
    <p>I am getting NullPointerException at setAdapter in my listview. I would really appreciate it if someone could help me out. My files are as follows:</p> <p>MainActivity.java</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Create the adapter that will return a fragment for each of the three // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter( getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); MainActivityContext=this; callGeolocationApi1(); ListView categoryList = (ListView) this.findViewById(R.id.listView); CategoryAdapter categoryAdapter = new CategoryAdapter(this, R.layout.category2_row_layout, getCategoriesList()); //java.lang.NullPointerException occurs here categoryList.setAdapter(categoryAdapter); } private List&lt;String&gt; getCategoriesList() { List&lt;String&gt; strlist = new ArrayList&lt;String&gt;(); strlist.add("str1"); strlist.add("str2"); return strlist; } </code></pre> <p>fragment_main_dummy.xml</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/orange" tools:context=".MainActivity"&gt; &lt;ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/listView" android:layout_gravity="center" tools:listitem="@layout/category2_row_layout"/&gt; </code></pre> <p></p> <p>category2_row_layout.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="6dip" android:background="#00000000"&gt; &lt;TextView android:id="@+id/category_name" android:layout_width="200dip" android:layout_height="wrap_content" android:textSize="20sp" android:layout_marginTop="10dip" android:scrollbars="vertical" android:fadingEdge="vertical" android:layout_alignParentLeft="true" android:background="#00000000" /&gt; &lt;ImageButton android:id="@+id/category_delete_button" android:background="#00000000" android:src="@drawable/settings" android:layout_width="50dip" android:layout_height="50dip" android:scrollbars="vertical" android:fadingEdge="vertical" android:layout_alignParentRight="true" android:focusable="false" android:focusableInTouchMode="false" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Logcat - <a href="http://pastebin.com/phLYcPC8" rel="nofollow">http://pastebin.com/phLYcPC8</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload