title: Initialisation of ImageView in Kotlin
body: <p>I am trying to display the bitmap in an ImageView.</p>
  <p>The following XML code is the ImageView.</p>
  <pre><code>&lt;ImageView
          android:id=&quot;@+id/image&quot;
          android:layout_width=&quot;100dp&quot;
          android:layout_height=&quot;100dp&quot;
          android:layout_centerInParent=&quot;true&quot; /&gt;
  </code></pre>
  <p>I lateinit the image view in MainActivity class as:</p>
  <pre><code>private lateinit var image: ImageView
  </code></pre>
  <p>I have perfect bitmap, there is no error in bitmap. The bitmap is passed from the a view kotlin class to the MainActivity.kt's &quot;show_result&quot; function.
  The following function is in MainActivity.kt</p>
  <pre><code>fun show_result(bm: Bitmap){
      image = findViewById(R.id.image)
      image.setImageBitmap(bm)
      }
  </code></pre>
  <p>Then,
  I got the following error, when I called the show_result function.
  Error:</p>
  <pre><code>E/InputEventReceiver: Exception dispatching input event.
  E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
  E/MessageQueue-JNI: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
          at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:152)
          at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:157)
          at android.content.Context.obtainStyledAttributes(Context.java:655)
          at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:839)
          at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
          at androidx.appcompat.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:630)
          at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:223)
          at com.app.symbolrecogniser.MainActivity.show_result(MainActivity.kt:75)
          at com.app.symbolrecogniser.CanV.saveBitmap(CanV.kt:424)
          at com.app.symbolrecogniser.CanV.touchUp(CanV.kt:196)
          at com.app.symbolrecogniser.CanV.onTouchEvent(CanV.kt:117)
          at android.view.View.dispatchTouchEvent(View.java:11776)
          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
          at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:448)
          at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1829)
          at android.app.Activity.dispatchTouchEvent(Activity.java:3307)
          at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
          at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:410)
          at android.view.View.dispatchPointerEvent(View.java:12015)
          at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4795)
          at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4609)
          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
          at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
          at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
          at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4293)
          at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
          at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4350)
          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
          at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
          at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
          at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
          at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6661)
          at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6635)
          at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6596)
          at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6764)
          at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186)
          at android.os.MessageQueue.nativePollOnce(Native Method)
          at android.os.Mess
  D/AndroidRuntime: Shutting down VM
  E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.app.symbolrecogniser, PID: 8853
      java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
          at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:152)
          at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:157)
          at android.content.Context.obtainStyledAttributes(Context.java:655)
          at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:839)
          at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
          at androidx.appcompat.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:630)
          at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:223)
          at com.app.symbolrecogniser.MainActivity.show_result(MainActivity.kt:75)
          at com.app.symbolrecogniser.CanV.saveBitmap(CanV.kt:424)
          at com.app.symbolrecogniser.CanV.touchUp(CanV.kt:196)
          at com.app.symbolrecogniser.CanV.onTouchEvent(CanV.kt:117)
          at android.view.View.dispatchTouchEvent(View.java:11776)
          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
          at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2968)
          at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2657)
          at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:448)
          at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1829)
          at android.app.Activity.dispatchTouchEvent(Activity.java:3307)
          at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
          at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:410)
          at android.view.View.dispatchPointerEvent(View.java:12015)
          at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4795)
          at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4609)
          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
          at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
          at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
          at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4293)
          at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
          at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4350)
          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
          at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4200)
          at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4166)
          at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4174)
          at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4147)
          at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6661)
          at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6635)
          at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6596)
          at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6764)
  E/AndroidRuntime:     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186)
          at android.os.MessageQueue.nativePollOnce(Native Method)
          at android.os.MessageQueue.next(MessageQueue.java:325)
          at android.os.Looper.loop(Looper.java:142)
          at android.app.ActivityThread.main(ActivityThread.java:6494)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
  </code></pre>
  <p>MainActivity.kt</p>
  <pre><code>class MainActivity : AppCompatActivity() {
  
      private lateinit var image: ImageView
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
      }
  
      fun show_result(bm: Bitmap){
          image = findViewById(R.id.image)
          image.setImageBitmap(bm)
      }
  </code></pre>
  <p>activity_main.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:id=&quot;@+id/canv_fix&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:orientation=&quot;vertical&quot;
      tools:context=&quot;.MainActivity&quot;
      tools:ignore=&quot;ContentDescription&quot;&gt;
  
      &lt;androidx.appcompat.widget.Toolbar
          android:id=&quot;@+id/toolbar&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:background=&quot;?attr/colorPrimary&quot;
          android:minHeight=&quot;?attr/actionBarSize&quot;
          android:theme=&quot;?attr/actionBarTheme&quot; /&gt;
  
  
      &lt;ImageView
          android:id=&quot;@+id/image&quot;
          android:layout_width=&quot;100dp&quot;
          android:layout_height=&quot;100dp&quot;
          android:layout_centerInParent=&quot;true&quot; /&gt;
  
      &lt;TextView
          android:id=&quot;@+id/label&quot;
          style=&quot;@style/TextAppearance.AppCompat.Headline&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_below=&quot;@+id/image&quot;
          android:layout_centerHorizontal=&quot;true&quot;
          android:layout_margin=&quot;10dp&quot; /&gt;
  
      &lt;TextView
          android:id=&quot;@+id/probability&quot;
          style=&quot;@style/TextAppearance.AppCompat.Body1&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_below=&quot;@+id/label&quot;
          android:layout_centerHorizontal=&quot;true&quot; /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>