java - Android ListView won't populate and throws error when extending AppCompatActivity -


i have issue trying populate custom listview while extending appcompatactivity. when extend listactivity listview populates no issues. need extend other activities listactivity. when run code, error is:

java.lang.runtimeexception: unable start activity componentinfo{net.package.twitter/net.package.twitter.main}: java.lang.nullpointerexception: attempt invoke virtual method 'int android.view.viewgroup.getpaddingleft()' on null object reference

caused by: java.lang.nullpointerexception: attempt invoke virtual method 'int android.view.viewgroup.getpaddingleft()' on null object reference @ net.package.twitter.main.oncreate(main.java:16)

here main class:

package net.package.twitter;  import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.widget.listview; import android.widget.simpleadapter;  import java.util.arraylist; import java.util.hashmap;  public class main extends appcompatactivity {  @override public void oncreate(bundle savedinstancestate) { setcontentview(r.layout.custom_list_view); arraylist<hashmap<string, string>> list = (arraylist<hashmap<string, string>>) getintent().getserializableextra("twitter");     listview ls = (listview)findviewbyid(r.id.list);     super.oncreate(savedinstancestate);      system.out.println(list.tostring());     final simpleadapter adapter = new simpleadapter(             this,             list,             r.layout.custom_row_view,             new string[]{"user", "time", "text", "screen_name"},             new int[]{r.id.text1, r.id.text2, r.id.text3, r.id.text4}     );     ls.setadapter(adapter); }  } 

here activity_main.xml:

<?xml version="1.0" encoding="utf-8"?> <relativelayout 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:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="net.package.twitter.main">  <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="hello world!" />  <listview android:id="@+id/list"     android:layout_width="383dp"     android:layout_height="380dp"     android:background="#ffffff"     android:drawselectorontop="false"> </listview> </relativelayout> 

here custom_row_view.xml (custom control of each entry of listview):

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">  <textview android:id="@+id/text1"     android:textsize="16sp"     android:textstyle="bold"     android:textcolor="#000000"     android:layout_width="fill_parent"     android:layout_height="fill_parent"/> <!--tweet account--> <textview android:id="@+id/text4"     android:typeface="serif"     android:textsize="12sp"     android:textstyle="bold"     android:layout_width="wrap_content"     android:layout_height="wrap_content"/> <!--tweet @ name--> <!--tweet time--> <textview android:id="@+id/text3"     android:typeface="sans"     android:textsize="15sp"     android:textstyle="italic"     android:layout_width="wrap_content"     android:layout_height="wrap_content"/>  <textview android:id="@+id/text2"     android:textsize="12sp"     android:textstyle="bold"     android:layout_width="wrap_content"     android:layout_height="fill_parent"/> <!--tweet contect-->  </linearlayout> 

if tell me why giving me error great, thanks!

put

super.oncreate(savedinstancestate);  

right before

setcontentview(r.layout.custom_list_view);  

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -