0

I imported retrofi2.Callback and I still get this error unresolved reference: enqueue this is the code of the login class

  import android.content.Intent
  import android.support.v7.app.AppCompatActivity
  import android.os.Bundle
  import android.provider.ContactsContract
  import android.widget.Button
  import android.widget.EditText
  import android.widget.TextView
  import android.widget.Toast
  import com.cbmis.imageapp.Common.Common
  import com.cbmis.imageapp.Model.APIResponse
  import com.cbmis.imageapp.Remote.IMyAPI
  import kotlinx.android.synthetic.main.activity_login.*
  import retrofit2.Call
  import retrofit2.Callback
  import retrofit2.Response 

class LoginActivity : AppCompatActivity() {

 internal lateinit var mService:IMyAPI
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_login)
    //initservice
    mService = Common.api

    //Event
 txtregister.setOnClickListener { startActivity(Intent(this@LoginActivity,RegisterActivity::class.java))
 finish()
 }
  btn_login.setOnClickListener { authentificateUser(findViewById<TextView>(R.id.email).text.toString(), findViewById<TextView>(R.id.password).text.toString()) }

    }



private fun authentificateUser(email: String, password: String) {

    mService.loginUser(email, password)
            .enqueue(object :Callback<APIResponse> {
                override fun onFailure(call: Call<APIResponse>?, t: Throwable?) {
                   Toast.makeText(this@LoginActivity,t!!.message,Toast.LENGTH_SHORT).show()
                }

                override fun onResponse(call: Call<APIResponse>?, response: Response<APIResponse>?) {
                    if (response!!.body()!!.error)
                        Toast.makeText(this@LoginActivity,response!!.body()!!.errr_msg,Toast.LENGTH_SHORT).show()
                    else
                        Toast.makeText(this@LoginActivity, "Login Success!",Toast.LENGTH_SHORT).show()

                }

         })
}

}

and this is the interface/

interface IMyAPI {
@FormUrlEncoded
@POST("signup.php")
fun registerUser(@Field("email") email:String,@Field("name")name:String,@Field("password") password:String,@Field("dateofbirth") dateofbirth:String,@Field("genderM") genderM:String,@Field("genderF") genderF:String):Class<APIResponse>

@FormUrlEncoded
@POST("login.php")
fun loginUser(@Field("email") email:String,@Field("password") password:String):Class<APIResponse>

}

Any solutions can be proposed to solve this problem

2
  • 1
    First, you should post your code as text instead of an image. Second, could you show the declaration of the loginUser method? Commented Aug 12, 2018 at 10:40
  • I edited the post Commented Aug 12, 2018 at 14:25

1 Answer 1

3

You should be returning a Retrofit Call from your API's functions:

interface IMyAPI {

    @FormUrlEncoded
    @POST("signup.php")
    fun registerUser(/* params */) : Call<APIResponse>


    @FormUrlEncoded
    @POST("login.php")
    fun loginUser(/* params */): Call<APIResponse>

}
Sign up to request clarification or add additional context in comments.

1 Comment

I didn't pay attention

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.