Eu estou recebendo esse erro do título do tópico ao tentar executar minha aplicação, logo em seguida ela para, alguém aqui sabe me dizer o que está acontecendo?
Retorno completo:
Classe MainActivity.kt
package tk.thallyssonklein.kapp
import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import com.google.firebase.database.*
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*
class MainActivity : AppCompatActivity() {
var preferences: SharedPreferences = getSharedPreferences("NOTIFICATIONS", MODE_PRIVATE)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
getDataFromServer()
}
fun getDataFromServer() {
var database: FirebaseDatabase = FirebaseDatabase.getInstance()
var movements: DatabaseReference = database.getReference("movements")
var workouts: DatabaseReference = database.getReference("workouts")
var childrenOfMovements: MutableList<Movement> = ArrayList()
var childrenOfWorkouts: MutableList<String> = ArrayList()
movements.orderByKey().addListenerForSingleValueEvent(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
if (dataSnapshot.exists()) {
for (data in dataSnapshot.children) {
childrenOfMovements.add(Movement(data.key,data.value.toString()))
}
var haveLearning: Boolean = false
var learning: String = ""
for(mov in childrenOfMovements){
if(mov.status.equals("learning")){
haveLearning = true
learning = mov.name
}
}
var movementOfTheDay: String = ""
if(haveLearning.not()) {
val i: Int = Random().nextInt(0 - childrenOfMovements.size) + childrenOfMovements.size
movementOfTheDay = childrenOfMovements[i].name
}else{
movementOfTheDay = learning
}
movDay.text = movementOfTheDay
}
}
override fun onCancelled(databaseError: DatabaseError) {
println("Cancelled")
}
})
workouts.orderByKey().addListenerForSingleValueEvent(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
if (dataSnapshot.exists()) {
var always: String = ""
var sorted: String = ""
for (data in dataSnapshot.children) {
if(data.value.toString().equals("morning")){
if(preferences.contains(data.key).not()){
preferences.edit().putString(data.key.toString(),data.value.toString()).apply()
}
}else if(data.value.toString().equals("sort")){
childrenOfWorkouts.add(data.key)
val i: Int = Random().nextInt(0 - childrenOfWorkouts.size) + childrenOfWorkouts.size
sorted = childrenOfWorkouts[i]
}
workDay.text = sorted +" or "+always
}
}
}
override fun onCancelled(databaseError: DatabaseError) {
println("Cancelled")
}
})
}
fun notification(ticker: String, contentTitle: String, contentText: String){
val intent = Intent()
val pending = PendingIntent.getActivity(this@MainActivity,0,intent,0)
val notification = Notification.Builder(this@MainActivity).setTicker(ticker).setContentTitle(contentTitle)
.setContentText(contentText)
.setContentIntent(pending).notification
notification.flags = Notification.FLAG_AUTO_CANCEL
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(0,notification)
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="tk.thallyssonklein.kapp.MainActivity">
<TextView
android:id="@+id/movDay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:text="Movement of the day: loading..." />
<TextView
android:id="@+id/workDay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/movDay"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:text="Workout of the day: loading..." />
</android.widget.RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tk.thallyssonklein.kapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Movement.kt
package tk.thallyssonklein.kapp
/**
* Created by thall on 11/01/2018.
*/
class Movement{
var name: String = ""
var status: String = ""
constructor(name: String, status: String){
this.name = name
this.status = status
}
}