I have been trying to solve a problem for a few hours now, but I failed to figure it out.i try a set adapter for expandable list view but i take this error. thanks. "Attempt to invoke virtual method 'void android.widget.ExpandableListView.setAdapter(android.widget.ExpandableListAdapter)' on a null object reference"
Main_Activity
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
//create menu items; itemAnasayfa = new ResideMenuItem(this, R.drawable.icon_home, "Ana Sayfa"); itemRastgele = new ResideMenuItem(this, R.drawable.icon_profile, "Random tarif bul"); itemEncok = new ResideMenuItem(this, R.drawable.icon_calendar, "En cok begenilenler"); itemTarifyaz = new ResideMenuItem(this, R.drawable.icon_settings, "tarif Yaz");
public ResideMenu getResideMenu(){ return resideMenu;} }
Adapter Class
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context cont; private List listDataHeader; private HashMap> listHashMap;
public ExpandableListAdapter(Context cont, List listDataHeader, HashMap> listHashMap) { this.cont = cont; this.listDataHeader = listDataHeader; this.listHashMap = listHashMap; }
@Override public int getGroupCount() { return listDataHeader.size(); }
@Override public int getChildrenCount(int i) { return listHashMap.get(listDataHeader.get(i)).size(); }
@Override public Object getGroup(int i) { return listDataHeader.get(i); }
@Override public Object getChild(int i, int i1) { // i=group position i=item position return listHashMap.get(listDataHeader.get(i)).get(i1); }
@Override public long getGroupId(int i) { return i; }
@Override public long getChildId(int i, int i1) { return i1; }
@Override public boolean hasStableIds() { return false; }
@Override public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) { String headerTitle=(String)getGroup(i);
if (view==null){ LayoutInflater inflater1=(LayoutInflater)this.cont.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view=inflater1.inflate(R.layout.list_group,null);
@Override public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) { final String childText=(String)getChild(i,i1);
if (view==null){ LayoutInflater inflater1=(LayoutInflater)this.cont.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view=inflater1.inflate(R.layout.list_item,null);
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.yeni, PID: 2404 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.yeni/com.yeni.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ExpandableListView.setAdapter(android.widget.ExpandableListAdapter)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ExpandableListView.setAdapter(android.widget.ExpandableListAdapter)'
on a null object reference at com.yeni.MainActivity.onCreate(MainActivity.java:55) at android.app.Activity.performCreate(Activity.java:6662) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
No comments:
Post a Comment