Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to establish RethinkDB connection in Kotlin #2

Open
omarhassan91 opened this issue Mar 23, 2021 · 0 comments
Open

Trying to establish RethinkDB connection in Kotlin #2

omarhassan91 opened this issue Mar 23, 2021 · 0 comments

Comments

@omarhassan91
Copy link

Hello!

I'm relatively new to using Kotlin, and right now I am trying to develop an application that establishes a connection with a RethinkDB server that I have created on my network. I was also following this guide: https://rethinkdb.com/blog/alt-jvm-driver/ . Here's the code that I've tried so far:

import android.os.AsyncTask
import android.os.Bundle
import android.os.StrictMode
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.rethinkdb.RethinkDB.r
import kotlinx.android.synthetic.main.activity_gps.*
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.toast
import org.jetbrains.anko.uiThread


import com.rethinkdb.net.Connection



class ActivityGPS : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_gps)

        val actionBar = supportActionBar

        actionBar!!.title = "GPS Tracker"
        actionBar.setDisplayHomeAsUpEnabled(true)


        class doAsync(val handler: () -> Unit) : AsyncTask<Void, Void, Void>() {
            override fun doInBackground(vararg params: Void?): Void? {
                handler()
                return null
            }
        }

        button.setOnClickListener{
            doAsync {
                val conn = r.connection().hostname("192.168.0.50").connect()
                //Database.query("test1").insert("TEST1").run()
                //val selected = Database.query("test1").get(id).one<ActivityGPS>()
            }.execute()
        }
    }
}

Basically what I have going on here is that I created a button within the fragment that I'm working in, and that button is supposed to invoke an Asynchronous function that establishes a connection to the RethinkDB server that I have created. I also made sure to import RethinkDB by using import com.rethinkdb.RethinkDB.r

However when I run this in the Android Emulator using a debugger, I get the following error message:

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
    Process: com.example.adm3000, PID: 10176
    java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$4.done(AsyncTask.java:415)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
     Caused by: com.rethinkdb.gen.exc.ReqlDriverError: java.security.spec.InvalidKeySpecException: Could not generate secret key
        at com.rethinkdb.net.Crypto.pbkdf2(Crypto.java:113)
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse.nextState(HandshakeProtocol.java:148)
        at com.rethinkdb.net.HandshakeProtocol.doHandshake(HandshakeProtocol.java:40)
        at com.rethinkdb.net.Connection.connect(Connection.java:118)
        at com.rethinkdb.net.Connection$Builder.connect(Connection.java:568)
        at com.example.adm3000.ActivityGPS$onCreate$1$1.invoke(ActivityGPS.kt:40)
        at com.example.adm3000.ActivityGPS$onCreate$1$1.invoke(ActivityGPS.kt:19)
        at com.example.adm3000.ActivityGPS$onCreate$doAsync.doInBackground(ActivityGPS.kt:33)
        at com.example.adm3000.ActivityGPS$onCreate$doAsync.doInBackground(ActivityGPS.kt:31)
        at android.os.AsyncTask$3.call(AsyncTask.java:394)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:923) 
     Caused by: java.security.spec.InvalidKeySpecException: Could not generate secret key
        at javax.crypto.SecretKeyFactory.generateSecret(SecretKeyFactory.java:535)
        at com.rethinkdb.net.Crypto.pbkdf2(Crypto.java:109)
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse.nextState(HandshakeProtocol.java:148) 
        at com.rethinkdb.net.HandshakeProtocol.doHandshake(HandshakeProtocol.java:40) 
        at com.rethinkdb.net.Connection.connect(Connection.java:118) 
        at com.rethinkdb.net.Connection$Builder.connect(Connection.java:568) 
        at com.example.adm3000.ActivityGPS$onCreate$1$1.invoke(ActivityGPS.kt:40) 
        at com.example.adm3000.ActivityGPS$onCreate$1$1.invoke(ActivityGPS.kt:19) 
        at com.example.adm3000.ActivityGPS$onCreate$doAsync.doInBackground(ActivityGPS.kt:33) 
        at com.example.adm3000.ActivityGPS$onCreate$doAsync.doInBackground(ActivityGPS.kt:31) 
        at android.os.AsyncTask$3.call(AsyncTask.java:394) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:923) 
     Caused by: java.lang.IllegalArgumentException: password empty
        at com.android.org.bouncycastle.jcajce.provider.symmetric.PBEPBKDF2$BasePBKDF2.engineGenerateSecret(PBEPBKDF2.java:237)
        at javax.crypto.SecretKeyFactory.generateSecret(SecretKeyFactory.java:524)
        at com.rethinkdb.net.Crypto.pbkdf2(Crypto.java:109) 
        at com.rethinkdb.net.HandshakeProtocol$WaitingForAuthResponse.nextState(HandshakeProtocol.java:148) 
        at com.rethinkdb.net.HandshakeProtocol.doHandshake(HandshakeProtocol.java:40) 
        at com.rethinkdb.net.Connection.connect(Connection.java:118) 
        at com.rethinkdb.net.Connection$Builder.connect(Connection.java:568) 
        at com.example.adm3000.ActivityGPS$onCreate$1$1.invoke(ActivityGPS.kt:40) 
        at com.example.adm3000.ActivityGPS$onCreate$1$1.invoke(ActivityGPS.kt:19) 
        at com.example.adm3000.ActivityGPS$onCreate$doAsync.doInBackground(ActivityGPS.kt:33) 
        at com.example.adm3000.ActivityGPS$onCreate$doAsync.doInBackground(ActivityGPS.kt:31) 
        at android.os.AsyncTask$3.call(AsyncTask.java:394) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:923) 

I tried really hard researching what this 'Could not generate secret key' error is or why it's being thrown, but there's very little documentation regarding this specific error in Android Studio. Would you happen to know why this error is being thrown, and how I can successfully establish a connection to my database using Kotlin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant