'Unresolved reference when trying to create items to aws amplify using android studio
I'm trying to create a simple android app that i can use to store item to a aws amplify database by giving the item a code and a name. Only problem is that when i run my code i get the error "Unresolved reference: Code". So i'm struggling to figure out why the .Code is not recognised. My code is below. Thank you in advance.
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.amplifyframework.AmplifyException
import com.amplifyframework.api.aws.AWSApiPlugin
import com.amplifyframework.core.Amplify
import com.amplifyframework.datastore.AWSDataStorePlugin
import android.util.Log
import com.amplifyframework.datastore.generated.model.Product
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
try {
Amplify.addPlugin(AWSApiPlugin()) // UNCOMMENT this line once backend is deployed
Amplify.addPlugin(AWSDataStorePlugin())
Amplify.configure(applicationContext)
Log.i("Amplify", "Initialized Amplify")
} catch (e: AmplifyException) {
Log.e("Amplify", "Could not initialize Amplify", e)
}
Create()
setContentView(R.layout.activity_main)
}
}
fun Create() {
val item: Product = Product.builder()
.Code("123456")
.Name("product1")
.build()
Amplify.DataStore.save(
item,
{ success -> Log.i("Amplify", "Saved item: " + success.item().name) },
{ error -> Log.e("Amplify", "Could not save item to DataStore", error) }
)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
