0

I have 2 classes:

object TrimNCompressConstants {
  var REQUEST_CODE = 101
  var EXTRA_VIDEO_PATH = "EXTRA_VIDEO_PATH"
  var EXTRA_MESSAGE = "EXTRA_MESSAGE"
  var RESULT_SUCCESS = 102 
}

and

class VideoUtil (var context : Context?) {
  fun show (code : Int) {
    TrimNCompressConstants.REQUEST_CODE = code
  }
}

When in call show(), it gives an error for TrimNCompressConstants.REQUEST_CODE = code:

java.lang.ExceptionInInitializerError

Can anybody help on this?

Thanks.

Alex Romanov
  • 11,453
  • 6
  • 48
  • 51
GeekyInt
  • 393
  • 4
  • 9
  • 16
    Why do you use class named *Constants* to store mutable variables? – Alex Romanov Jun 21 '17 at 13:08
  • Show your stack trace. – Miha_x64 Jun 21 '17 at 13:15
  • an `ExceptionInInitializerError` is occurs in static *initializer / static initialization*, I don't know why you are reported such an error? – holi-java Jun 21 '17 at 13:16
  • 2
    It tested your code and it works for me –  Jun 21 '17 at 14:26
  • I admit I don;t know a lot about how Kotlin initializes properties in an object but it almost looks like it is happening after you access it. Can you try annotating your vars in your object with [`@JvmStatic`](https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#static-methods) and let us know if that fixes it? – Dr. Nitpick Jun 25 '17 at 03:45

0 Answers0