Проблема с базовым адаптером в Котлине - PullRequest
0 голосов
/ 27 января 2019

Я использую listview в моем проекте Android.Для этого я создал дочерний элемент BaseAdapter.Но я получаю сообщение об ошибке и приложение падает.

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 Процесс: com.example.foodtaskerkotlin, PID: 25975java.lang.NullPointerException: попытка вызвать виртуальный метод int android.view.View.getImportantForAccessibility () для нулевой ссылки на объект на android.widget.AbsListView.obtainView (AbsListView.java:2379) на android.widget.ListView.makeAndAddView (ListView.java:1970) в android.widget.ListView.fillDown (ListView.java:704) в android.widget.ListView.fillFromTop (ListView.java:765) в android.widget.ListView.layoutChildren (ListView.java: 1744) на android.widget.AbsListView.onLayout (AbsListView.java:2161) на android.view.View.layout (View.java:17523) на android.view.ViewGroup.layout (ViewGroup.java:5612) на android.widget.LinearLayout.setChildFrame (LinearLayout.java:1741) в android.widget.LinearLayout.layoutVertical (LinearLayout.java:1585) в android.widget.LinearLayout.onLayout (LinearLayout.java:1494) в иroid.view.View.layout (View.java:17523) в android.view.ViewGroup.layout (ViewGroup.java:5612) в android.widget.FrameLayout.layoutChildren (FrameLayout.java:323) в android.widget.FrameLayout.onLayout (FrameLayout.java:261) на android.view.View.layout (View.java:17523) на android.view.ViewGroup.layout (ViewGroup.java:5612) на android.widget.LinearLayout.setChildFrame (LinearLayout.Java: 1741) в android.widget.LinearLayout.layoutVertical (LinearLayout.java:1585) в android.widget.LinearLayout.onLayout (LinearLayout.java:1494) в android.view.View.layout (View.java:17523) вandroid.view.ViewGroup.layout (ViewGroup.java:5612) на android.support.v4.widget.DrawerLayout.onLayout (DrawerLayout.java:1231) на android.view.View.layout (View.java:17523) на android.view.ViewGroup.layout (ViewGroup.java:5612) в android.widget.FrameLayout.layoutChildren (FrameLayout.java:323) в android.widget.FrameLayout.onLayout (FrameLayout.java:261) в android.view.View.макет (View.java:17523) на android.view.ViewGroup.layout (ViewGroup.java:5612) в android.widget.LinearLayout.setChildFrame (LinearLayout.java:1741) в android.widget.LinearLayout.layoutVertical (LinearLayout.java:1585) в android.widget.LinearLayout.LLout (onLayout (onLayout): 1494) на android.view.View.layout (View.java:17523) на android.view.ViewGroup.layout (ViewGroup.java:5612) на android.widget.FrameLayout.layoutChildren (FrameLayout.java:323) на android.widget.FrameLayout.onLayout (FrameLayout.java:261) в android.view.View.layout (View.java:17523) в android.view.ViewGroup.layout (ViewGroup.java:5612) в android.widget.LinearLayout.setChildFrame (LinearLayout.java:1741) в android.widget.LinearLayout.layoutVertical (LinearLayout.java:1585) в android.widget.LinearLayout.onLayout (LinearLayout.java:1494) в android.view.View.layout (представление.: 17523) в android.view.ViewGroup.layout (ViewGroup.java:5612) в android.widget.FrameLayout.layoutChildren (FrameLayout.java:323) в android.widget.FrameLayout.onLayout (FrameLayout.java:261) в com.android.internal.policy.DecorView.onLayout (DecorView.java:724) в android.view.View.layout (View.java:17523) в android.view.ViewGroup.layout (ViewGroup.java:5612) в android.view.ViewRootImpl.performLayout (ViewRootImpl.java:2342) в android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2069)на android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1246) на android.view.ViewRootImpl $ TraversalRunnable.run (ViewRootImpl.java:6301) на android.view.Choreographer $ CallbackRecord.run) в Chorere:android.view.Choreographer.doCallbacks (Choreographer.java:683) в android.view.Choreographer.doFrame (Choreographer.java:619) в android.view.Choreographer $ FrameDisplayEventReceiver.run (хореограф.roid.57): 8.Handler.handleCallback (Handler.java:751) в android.os.Handler.dispatchMessage (Handler.java:95) в android.os.Looper.loop (Looper.java:154) в android.app.ActivityThread.main (ActivityThread.java:6077) в java.lang.reflect.Method.invoke (собственный метод) в 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)

...