By user8950495


2019-01-27 14:11:53 8 Comments

I am using listview in my android project. For this I have created a child of BaseAdapter. But I am getting error and app is crashing.

override fun onActivityCreated(savedInstanceState: Bundle?) {
    super.onActivityCreated(savedInstanceState)

    val restaurantListView:ListView? = activity?.findViewById(R.id.restaurant)
    restaurantListView?.adapter = RestaurantAdapter()
    }
}

class RestaurantAdapter:BaseAdapter()
{
override fun getCount(): Int {
return 3
}

override fun getItem(position: Int): Any {
    return Any()
}

override fun getItemId(position: Int): Long {
    return 0
}

override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? {
    return null
}
}

2019-01-27 19:32:50.372 25975-25975/com.example.foodtaskerkotlin E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.foodtaskerkotlin, PID: 25975 java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference at android.widget.AbsListView.obtainView(AbsListView.java:2379) at android.widget.ListView.makeAndAddView(ListView.java:1970) at android.widget.ListView.fillDown(ListView.java:704) at android.widget.ListView.fillFromTop(ListView.java:765) at android.widget.ListView.layoutChildren(ListView.java:1744) at android.widget.AbsListView.onLayout(AbsListView.java:2161) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585) at android.widget.LinearLayout.onLayout(LinearLayout.java:1494) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585) at android.widget.LinearLayout.onLayout(LinearLayout.java:1494) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1231) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585) at android.widget.LinearLayout.onLayout(LinearLayout.java:1494) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585) at android.widget.LinearLayout.onLayout(LinearLayout.java:1494) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at com.android.internal.policy.DecorView.onLayout(DecorView.java:724) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2342) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2069) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6301) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871) at android.view.Choreographer.doCallbacks(Choreographer.java:683) at android.view.Choreographer.doFrame(Choreographer.java:619) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) 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:866) 2019-01-27 19:32:50.372 25975-25975/com.example.foodtaskerkotlin E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

0 comments

Related Questions

Sponsored Content

2 Answered Questions

2 Answered Questions

App crashes on a particular layout when minifyEnable is set to true

  • 2018-12-16 05:48:30
  • Abhi
  • 160 View
  • 0 Score
  • 2 Answer
  • Tags:   android minify

1 Answered Questions

[SOLVED] Binary XML file line #28: Binary XML file line #28: Error inflating class <unknown>

  • 2018-05-18 05:43:55
  • Александр Волошиновский
  • 551 View
  • 1 Score
  • 1 Answer
  • Tags:   android

1 Answered Questions

Android messenger app crashes after signing in

  • 2018-05-06 04:11:31
  • Dipjyoti Biswas
  • 52 View
  • 1 Score
  • 1 Answer
  • Tags:   android crash

1 Answered Questions

How to prevent Android GreedoLayout Out-of-bounds exception?

Sponsored Content