gpt4 book ai didi

android - "too many arguments for public constructor string() defined "Kotlin问题

转载 作者:行者123 更新时间:2023-12-02 13:19:34 24 4
gpt4 key购买 nike

我有点迷茫,创建一个数据库,用户必须在其中保存研究结果,他将从各种小部件(例如微调器或 RG)中选择数据。如何编码 Int 或 String 类型的变量对我来说不是问题,但在 Spinner 数字选择器和 RG 的情况下。有人可以纠正我吗?

主要 Activity

    Package com.example.apkadlapacjenta

import android.os.Bundle
import com.google.android.material.snackbar.Snackbar
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase

import kotlinx.android.synthetic.main.activity_historia_pomiarow.*


class HistoriaPomiarow : AppCompatActivity() {

var listaWynikow = ArrayList<FIrebaseVal>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_historia_pomiarow)
setSupportActionBar(toolbar)

//Wczytujemy baze danych
LoadQuery("%")

supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
override fun onResume() {
super.onResume()
LoadQuery("%")
}

private fun LoadQuery(title:String){
val dbManager = DbMenager(this)
val projections = arrayOf("Id", "Stezenie", "Zegar","Data","Posilek","Stres","Samopoczucie","Hiperglikemia","Insulina")
val cursor =
dbManager.Query(projections, "Title like?", selectionArgs , "Title")
listaWynikow.clear()
if (cursor.moveToFirst()) {
do {
***val ID = cursor.getInt(cursor.getColumnIndex("Id")) ---> HERE i have problem
val Stezenie = cursor.getInt(cursor.getColumnIndex("Stezenie")) ---> NumberPicker
val Zegar = cursor.getString(cursor.getColumnIndex("Zegar"))
val Data =cursor.getString(cursor.getColumnIndex("Data"))
val Posilek = cursor.getString(cursor.getColumnIndex("Posilek")) -----> RB
val Stres = cursor.getString(cursor.getColumnIndex("Stres"))
val Samopoczucie = cursor.getString(cursor.getColumnIndex("Samopoczucie")) --->SPINNER
val Hiperglikemia = cursor.getString(cursor.getColumnIndex("Hiperglikemia"))--->SPINNER
val Insulina = cursor.getInt(cursor.getColumnIndex("Insulina")) --->SPINNER
**listaWynikow.add(Note(ID, Stezenie, Zegar,Data,Posilek,Stres,Samopoczucie,Hiperglikemia,Insulina))
} while (cursor.moveToNext())*****
}
}

}

“---> Spinner、Numberpicker、RG”等不是代码

数据库管理器
    package com.example.apkadlapacjenta

import android.content.ContentValues
import android.content.Context
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.database.sqlite.SQLiteQueryBuilder
import android.widget.RadioGroup
import android.widget.Toast

class DatebaseMenagerPomiary {

//Database name
var dbName = "Historia Pomiarów"
//table name
var dbTable = "Wyniki"
//kolumny
var colID = "Id"
var colStezenie = "Stezenie"
var colZegar = "Zegar"
var colData = "Data"
var colPosilek = "Posilek"
var colStres = "Stres"
var colSamopoczucie = "Samopoczucie"
var colHiperglikemia = "Hiperglikemia"
var colInsulina = "Insulina"

//wersja
var dbVersion = 1

//Tworzymy tabele
val sqlCreateTable =
"CREATE TABLE$dbTable($colID INTEGER PRIMARY KEY, $colStezenie NumberPicker, $colZegar TEXT, $colData TEXT, $colPosilek RADIO GROUP, $colStres SPINNER,$colSamopoczucie SPINNER, $colHiperglikemia SPINNER, $colInsulina TEXT)"

var sqlDB: SQLiteDatabase? = null
constructor(context: Context){
var db = DatabaseHelperWyniki(context)
sqlDB = db.writableDatabase
}


inner class DatabaseHelperWyniki : SQLiteOpenHelper {
var context: Context? = null
constructor(context: Context) : super(context, dbName, null, dbVersion) {
this.context = context
}

override fun onCreate(db: SQLiteDatabase?) {
db!!.execSQL(sqlCreateTable)
Toast.makeText(this.context,"baza danych utworzona...",Toast.LENGTH_SHORT).show()

}

override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
db!!.execSQL("zamknij tabele jeśli nie istnieje" + dbTable)
}


}

fun insert(values:ContentValues):Long{
val ID = sqlDB!!.insert(dbTable,"",values)
return ID
}
fun Query(projection:Array<String>,selection:String,selectionArgs:Array<String>,sorOrder:String): Cursor {

val qb = SQLiteQueryBuilder();
qb.tables=dbTable
val cursor = qb.query(sqlDB,projection,selection,selectionArgs,null,null,sorOrder)
return cursor
}

fun delete(selection: String,selectionArgs: Array<String>):Int{
val count = sqlDB!!.delete(dbTable,selection,selectionArgs)
return count
}

fun update(values:ContentValues,selection: String,selectionArgs: Array<String>): Int {
val count = sqlDB!!.update(dbTable,values,selection,selectionArgs)
return count
}



}

节点类
NODE CLASS 

package com.example.apkadlapacjenta

import android.provider.MediaStore
import android.widget.NumberPicker
import android.widget.RadioGroup
import android.widget.Spinner

class FIrebaseVal(nodeID: Int, nodeNumberPicker:NumberPicker,nodezegar:String,nodedata:String,nodeposilek:RadioGroup,nodehiperglikemia:Spinner,nodestres:Spinner,nodesamopoczucie:Spinner,nodeinsulina:Int) {
var nodeID: Int?= nodeID
var nodeNumberPicker:NumberPicker?= nodeNumberPicker
var nodezegar:String?=nodezegar
var nodedata:String?=nodedata
var nodeposilek:RadioGroup?=nodeposilek
var nodehiperglikemia:Spinner?=nodehiperglikemia
var nodestres:Spinner?=nodestres
var nodesamopoczucie:Spinner?=nodesamopoczucie
var nodeinsulina:Int?=nodeinsulina
}

剩下的代码我知道怎么做,即适配器和各种功能,如 SearchView等,在 Numberpicker、Spinner 和 RG 编码方面需要帮助,因为在行中:
listaWynikow.add(Note(ID, Stezenie, Zegar,Data,Posilek,Stres,Samopoczucie,Hiperglikemia,Insulina))
} while (cursor.moveToNext())

我收到一个错误
“定义的公共(public)构造函数 string() 的参数太多”。

最佳答案

节点类的问题在这里你已经声明了总共 9 个参数:

class FIrebaseVal(nodeID: Int, nodeNumberPicker:NumberPicker,nodezegar:String,nodedata:String,nodeposilek:RadioGroup,nodehiperglikemia:Spinner,nodestres:Spinner,nodesamopoczucie:Spinner,nodeinsulina:Int)

但在这里您传递的 10 个参数请确认参数值。我无法理解变量名。
listaWynikow.add(Note(ID, Stezenie, Zegar,Data,Posilek,Stres,Samopoczucie,Hiperglikemia,Insulina))

关于android - "too many arguments for public constructor string() defined "Kotlin问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59694035/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com