Attempt to write to field 'int' on a null object reference

(wdb) #1

IDE: Fire
Version: Version (develop) built on talax, 20190425-190525. Commit e0b3c5f.
Target (If relevant): Android
I am trying to use my Result-enum within my Android application only when I am trying to use I am getting a NRE in the Android application when running it.

Expected Behavior:
I would expect that no NRE is being triggered and my completion handler is triggered

Actual Behavior:
Now when I call completion(.success("Bon Bini Beach")) I am getting the NRE:

!> Exception of type java.lang.NullPointerException on thread 0002 ()
!> Message: Attempt to write to field 'int uk.ix.androidapplication.Result.fValue' on a null object reference


  1. Start a new Android application
  2. Copy the code listed below
  3. Build and wait until the NRE is lsited
import java.util
import android.content
import android.os
import android.util
import android.view
import android.widget

/// An enm representing a typical error for a Result<T>
public enum ResultError: Swift.Error {
    case invalid(String)
    case parseError
    case networkError
    case notFound
    case cancelled

/// An enum representing either a failure with an explanatory error, or a success with a result value.
    public enum Result<Value> {
        case success(Value)
        case failure(ResultError)

        // MARK: Constructor

        /// Constructs a success wrapping a `value`.
        public init(value: Value) {
            self = .success(value)

        /// Constructs a failure wrapping an `error`.
        public init(error: ResultError) {
            self = .failure(error)

        // MARK: Helper methods
        public func dematerialize() throws -> Value {
            switch self {
                case let .success(value):
                return value
                case let .failure(error):
                throw error

    public class MainActivity: Activity {

        public override func onCreate(_ savedInstanceState: Bundle!) {
            ContentView = R.layout.main
            fetchData() { result in
            guard let locationStore = try? result.dematerialize(), let weakSelf = self else {
            android.util.Log.d("MAINACTIVITY", "locationStore: \(locationStore)")
    private func fetchData(completion completion: (Result<String>) -> ()) {
        completion(.success("Bon Bini Beach"))
(RemObjects) #2

Thanks, logged as bugs://82480

(RemObjects) #3

bugs://82480 got closed with status fixed.

1 Like