Koin version: 2.1.5
Instructions are missing from documentation here.
This is what I have:
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
startKoin {
// use AndroidLogger as Koin Logger - default Level.INFO
androidLogger()
// use the Android context given there
androidContext(this#MyApp)
// module list
modules(emptyList())
}
}
}
class MainActivity : AppCompatActivity() {
private val logger : Logger by inject()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
logger.debug("onCreate")
}
}
And looks like there is no instance of Logger in the dependency graph:
04-26 12:02:03.781 4672-4672/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 4672
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'org.koin.core.logger.Logger'. Check your definitions!
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'org.koin.core.logger.Logger'. Check your definitions!
at org.koin.core.scope.Scope.throwDefinitionNotFound(Scope.kt:247)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:216)
at org.koin.core.scope.Scope.get(Scope.kt:181)
at com.example.myapplication.MainActivity$$special$$inlined$inject$1.invoke(ComponentCallbackExt.kt:51)
at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
at com.example.myapplication.MainActivity.getLogger(MainActivity.kt)
at com.example.myapplication.MainActivity.onCreate(MainActivity.kt:17)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Why?
My understanding: this logger is used for internal Koin logging. I came to the conclusion by looking into source code. This logger can be used outside of Koin itself getKoin()._logger.info("hello world") but I doubt it was the library creator's intention.
Related
I am trying to get to the current location of the user. On running the app crashes. The map is working, it points to the default lat long i.e Sydney, But on trying to access current location app crashes. I have created the enableUserLocation method to check for permissions.
class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
private lateinit var mMap: GoogleMap
private lateinit var geofencingClient: GeofencingClient
private var FINE_LOCATION_ACCESS_REQUEST_CODE = 10001
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_maps)
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
val mapFragment = supportFragmentManager
.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)
geofencingClient = LocationServices.getGeofencingClient(this)
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
// Add a marker in Sydney and move the camera
val sydney = LatLng(-34.0, 151.0)
mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
enableUserLocation()
}
private fun enableUserLocation() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED
) {
mMap.isMyLocationEnabled = true
} else {
//Ask for permission
if (ActivityCompat.shouldShowRequestPermissionRationale(
this,
Manifest.permission.ACCESS_FINE_LOCATION
)
) {
//we need to show a user dialog that why the permission is needed and then ask for the permission
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
FINE_LOCATION_ACCESS_REQUEST_CODE
)
} else {
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
FINE_LOCATION_ACCESS_REQUEST_CODE
)
}
}
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
if (requestCode == FINE_LOCATION_ACCESS_REQUEST_CODE) {
if (grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//We have the permission
mMap.isMyLocationEnabled = true
} else {
//we do not have the permission
}
}
}
}
Here is the logcat error which says it's a runtime exception.
2020-05-21 14:01:05.064 7621-7628/? E/art: Failed sending reply to debugger: Broken pipe
2020-05-21 14:01:09.525 7621-7621/com.example.geofencedemo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.geofencedemo, PID: 7621
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.geofencedemo/com.example.geofencedemo.MapsActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: calling Fragment constructor caused an exception
at androidx.fragment.app.Fragment.instantiate(Fragment.java:541)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
at androidx.fragment.app.FragmentManagerImpl$6.instantiate(FragmentManagerImpl.java:2851)
at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManagerImpl.java:3196)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:134)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:357)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:336)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:777)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.example.geofencedemo.MapsActivity.onCreate(MapsActivity.kt:26)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at androidx.fragment.app.Fragment.instantiate(Fragment.java:523)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
at androidx.fragment.app.FragmentManagerImpl$6.instantiate(FragmentManagerImpl.java:2851)
at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManagerImpl.java:3196)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:134)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:357)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:336)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:777)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.example.geofencedemo.MapsActivity.onCreate(MapsActivity.kt:26)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/maps/SupportMapFragment$zzb;
at com.google.android.gms.maps.SupportMapFragment.<init>(Unknown Source)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at androidx.fragment.app.Fragment.instantiate(Fragment.java:523)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
at androidx.fragment.app.FragmentManagerImpl$6.instantiate(FragmentManagerImpl.java:2851)
at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManagerImpl.java:3196)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:134)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:357)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:336)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:777)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.example.geofencedemo.MapsActivity.onCreate(MapsActivity.kt:26)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment$zzb
at java.lang.VMClassLoader.findLoadedClass(Native Method)
2020-05-21 14:01:09.526 7621-7621/com.example.geofencedemo E/AndroidRuntime: at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:742)
at java.lang.ClassLoader.loadClass(ClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 30 more
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/dynamic/zza;
... 30 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.dynamic.zza" on path: DexPathList[[zip file "/data/app/com.example.geofencedemo-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.geofencedemo-2/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 30 more
package com.example.testapp
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.hanks.passcodeview.PasscodeView
class Main2Activity : AppCompatActivity() {
var EXTRA_TEXT ="fintech"
private var PRIVATE_MODE = 0
private val PREF_NAME = "myref"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val sharedPref: SharedPreferences = getSharedPreferences(PREF_NAME, PRIVATE_MODE)
var passcodeView=findViewById<PasscodeView>(R.id.passcodeView)
passcodeView.setPasscodeLength(4).listener = object :
PasscodeView.PasscodeViewListener{
override fun onSuccess(number: String?) {
if (sharedPref.getBoolean(PREF_NAME, false)) {
val homeIntent = Intent(applicationContext, AfterloginActivity::class.java)
homeIntent.putExtra("fintech",number)
startActivity(homeIntent)
finish()
} else {
setContentView(R.layout.activity_main2)
val editor = sharedPref.edit()
editor.putBoolean(PREF_NAME, true)
editor.apply()
}
}
override fun onFail() {
Toast.makeText(this#Main2Activity,"wrong",Toast.LENGTH_SHORT).show()
}
}
}
}
this my source code and i get this error:
Process: com.example.testapp, PID: 11939
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testapp/com.example.testapp.Main2Activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.hanks.passcodeview.PasscodeView com.hanks.passcodeview.PasscodeView.setPasscodeLength(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.hanks.passcodeview.PasscodeView com.hanks.passcodeview.PasscodeView.setPasscodeLength(int)' on a null object reference
at com.example.testapp.Main2Activity.onCreate(Main2Activity.kt:46)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
04-02 14:39:57.454 11939-11939/? I/Process: Sending signal. PID: 11939 SIG: 9
if i put "setContentView(R.layout.activity_main2)" below oncreate its work but i want to make it onetime login only so i put it under and then i got this error "java.lang.NullPointerException: Attempt to invoke virtual method 'com.hanks.passcodeview.PasscodeView com.hanks.passcodeview.PasscodeView.setPasscodeLength(int)' on a null object reference"
Thanks
Your error is caused by this line:
var passcodeView=findViewById<PasscodeView>(R.id.passcodeView)
You are trying to find a view when you have not setContentView for the activity.
If you don't call setContentView() all calls to findViewById() will return null. passcodeView being null is the reason for your NullPointerException.
There is no way to start the AfterloginActivity before setContentView() because you rely on passCodeView to add something to the Intent when you do homeIntent.putExtra("fintech",number).
I am trying to switch my app from Loaders to Room and ViewModels. I have written my own App class:
class App : Application() {
lateinit var database: AppDatabase
private set
override fun onCreate() {
super.onCreate()
instance = this
database = Room.databaseBuilder(this, AppDatabase::class.java, AppDatabase.NAME)
.build()
}
companion object {
lateinit var instance : App
}
}
And my view model:
open class BaseViewModel<TEntity, TDao: BaseDao<TEntity>, TRepo : Repository<TEntity, TDao>>(
app: App, protected val repository: TRepo) : AndroidViewModel(app) {
fun insert(entity: TEntity) {
repository.insert(entity)
}
fun update(entity: TEntity) {
repository.update(entity)
}
fun delete(entity: TEntity) {
repository.delete(entity)
}
}
class TimetableViewModel(app: App) : BaseViewModel<Timetable, TimetableDao, TimetableRepository>(
app, TimetableRepository(app.database)) {
internal val all: LiveData<List<Timetable>> = repository.getAll()
}
In MainActivity.onCreate() I initialize my TimetableViewModel by next line:
timetableVM = ViewModelProviders.of(this).get(TimetableViewModel::class.java)
But on launch the app crashes with log:
Caused by: java.lang.RuntimeException: Cannot create an instance of class com.contedevel.timetable.model.TimetableViewModel
at android.arch.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:201)
at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:134)
at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:102)
at com.contedevel.timetable.activity.MainActivity.onCreate(MainActivity.kt:187)
at android.app.Activity.performCreate(Activity.java:6757)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2702)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2810)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6312)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Caused by: java.lang.NoSuchMethodException: <init> [class android.app.Application]
at java.lang.Class.getConstructor0(Class.java:2204)
at java.lang.Class.getConstructor(Class.java:1683)
at android.arch.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:199)
at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:134)
at android.arch.lifecycle.ViewModelProvider.get(ViewModelProvider.java:102)
at com.contedevel.timetable.activity.MainActivity.onCreate(MainActivity.kt:187)
at android.app.Activity.performCreate(Activity.java:6757)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2702)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2810)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6312)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
I'm using firebase in my android project.
But this is what get when user trying to sign up in firebase using my application.
My errors log
09-15 13:54:23.992 2716-2716/com.example.err0r1096.tikteck E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.err0r1096.tikteck, PID: 2716
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: kotlin.KotlinNullPointerException
at com.example.err0r1096.tikteck.Login.LoginToFireBase(Login.kt:26)
at com.example.err0r1096.tikteck.Login.OneC(Login.kt:20)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
and this my code :
package com.example.err0r1096.tikteck
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_login.*
class Login : AppCompatActivity() {
private val mAuth: FirebaseAuth? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
}
fun OneC(view: View){
LoginToFireBase(etEmail.text.toString(),etPassword.text.toString())
}
fun LoginToFireBase(email:String,password:String){
mAuth!!.createUserWithEmailAndPassword(email,password)
.addOnCompleteListener(this){ task ->
if (task.isSuccessful){
Toast.makeText(applicationContext,"Successful login",Toast.LENGTH_LONG).show()
}
else
{
Toast.makeText(this,"Login UnSuccessful",Toast.LENGTH_LONG).show()
}
}
}
}
My application is crashing when user click on start button .
I think the problem is in my code and not on the firebase.
You can check the official doc:
Kotlin's type system is aimed to eliminate NullPointerException's from our code. The only possible causes of NPE's may be:
An explicit call to throw NullPointerException();
Usage of the !! operator that is described below;
External Java code has caused it;
There's some data inconsistency with regard to initialization (an uninitialized this available in a constructor is used somewhere).
Using: b!! it will return a non-null value of b or throw an NPE if b is null
Check your code (you are using kotlin as java)
mAuth!!.createUserWithEmailAndPassword(email,password)
Did you initialize mAuth anywhere? If not, the mAuth!! will throw a NullPointerException
Try declaring the widgets by,
fun onC (view: View) {
val emailTxt = findViewById<View>(R.id.etEmail) as EditText
val passwordTxt = findViewById<View>(R.id.etPassword) as EditText
val email = emailTxt.text.toString.trim()
val password = passwordTxt.text.toString.trim()
LoginToFireBase (email, password)
}
This may resolve your problem :)
I'm getting this error
FATAL EXCEPTION: main
Process: com.demo.gandharv.exkotlin, PID: 7742
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.pantelwar.gandharv.scobokotlin/com.demo.gandharv.exkotlin.RegisterActivity}: kotlin.KotlinNullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3095)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3351)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1796)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7230)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: kotlin.KotlinNullPointerException
at com.demo.gandharv.exkotlin.RegisterActivity.(RegisterActivity.kt:12)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1096)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3085)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3351)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1796)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7230)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
I have defined the RegisterActivity in my AndroidMenifest.xml.
I have no idea why i'm getting this error.
Here's my LoginActivity.kt
package com.demo.gandharv.exkotlin
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_login.*
class LoginActivity : AppCompatActivity() {
var email: String = ""
var password: String = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
loginButton.setOnClickListener {
email = emailEditText.text.toString()
password = passwordEditText.text.toString()
}
registerTextView.setOnClickListener {
val intent = Intent(this#LoginActivity, RegisterActivity::class.java)
startActivity(intent)
}
}
}