App build susscessful, but keeps stopping (App info , close app)
######################################
logs
W/rice.onlinesho: Accessing hidden method Landroid/graphics/Typeface;->createFromFamiliesWithDefault([Landroid/graphics/FontFamily;Ljava/lang/String;II)Landroid/graphics/Typeface; (light greylist, reflection)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pt.patrice.onlineshop, PID: 15717
java.lang.ExceptionInInitializerError
at com.pt.patrice.onlineshop.ArticleRepository.updateData(ArticleRepository.kt:23)
at com.pt.patrice.onlineshop.MainActivity.onCreate(MainActivity.kt:16)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: com.google.firebase.database.DatabaseException: Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your getInstance() call.
at com.google.firebase.database.FirebaseDatabase.getInstance(com.google.firebase:firebase-database@@19.2.1:97)
at com.google.firebase.database.FirebaseDatabase.getInstance(com.google.firebase:firebase-database@@19.2.1:57)
at com.pt.patrice.onlineshop.ArticleRepository$Singleton.(ArticleRepository.kt:13)
at com.pt.patrice.onlineshop.ArticleRepository.updateData(ArticleRepository.kt:23)
at com.pt.patrice.onlineshop.MainActivity.onCreate(MainActivity.kt:16)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
##################### Repository##############
package com.pt.patrice.onlineshop
import com.google.firebase.database.*
import com.pt.patrice.onlineshop.ArticleRepository.Singleton.articleList
import com.pt.patrice.onlineshop.ArticleRepository.Singleton.databaseRef
import com.pt.patrice.onlineshop.fragments.ArticleModel
import javax.security.auth.callback.Callback
class ArticleRepository {
object Singleton {
//se connecter a la reference "article"
val databaseRef = FirebaseDatabase.getInstance().getReference("articles")
// creer une liste qui va contenir nos articles
val articleList = arrayListOf<ArticleModel>()
}
fun updateData(callback:()->Unit) {
// absorber les donnees depuis la databaseRef -> liste d' articles
databaseRef.addValueEventListener(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
//retirer les anciennes
articleList.clear()
//recolter la liste
for (ds in snapshot.children) {
val article = ds.getValue(ArticleModel::class.java)
// verifier que l'article n'est pas null
if (article != null) {
// ajouter un article á notrd liste
articleList.add(article)
}
}
//actionner le callback
callback()
}
override fun onCancelled(snapshot: DatabaseError) {
TODO("Not yet implemented")
}
})
}
}
#############Main Actifity###########
package com.pt.patrice.onlineshop
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.pt.patrice.onlineshop.fragments.HomeFragment
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//Charger notre plante repository
val repo = ArticleRepository()
//mettre a jour laliste des articles
repo.updateData {
//injecter le fragment dans notre boite (fragment_container)
val transaction=supportFragmentManager.beginTransaction()
transaction.replace(R.id.fragment_container,HomeFragment(this))
transaction.addToBackStack(null)
transaction.commit()
}
}
}
1 post - 1 participant
Read full topic