IDE: Fire
Version: Version 10.0.0.2398 (develop) built on talax, 20190425-190525. Commit e0b3c5f.
Target (If relevant): Android
Description:
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
Steps:
- Start a new Android application
- Copy the code listed below
- Build and wait until the NRE is lsited
import java.util
import android.app
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!) {
super.onCreate(savedInstanceState)
ContentView = R.layout.main
fetchData() { result in
guard let locationStore = try? result.dematerialize(), let weakSelf = self else {
return
}
android.util.Log.d("MAINACTIVITY", "locationStore: \(locationStore)")
}
}
private func fetchData(completion completion: (Result<String>) -> ()) {
completion(.success("Bon Bini Beach"))
}
}