我正在制作一个迷你绘图游戏应用程序,并且我制作了此类来保存绘图路径及其相应颜色,现在我需要保存它,以便我的应用程序的其他用户可以获取该数据并实际查看绘图
COLUMN|VALUE
=============
C1|V1
C2|V2
但是当我执行class CustomPath(path: android.graphics.Path, paint: android.graphics.Paint)
时,其中array是ArrayList时,我会收到此错误
“ E / MessageQueue-JNI:com.google.firebase.database.DatabaseException:不支持序列化集合,请改用列表”
有没有更好的方法可以将此ArrayList保存在游戏的其他玩家可以获取其持有的数据的位置,从而使平局显示在各自的屏幕上?
代码:
myRefDraw?.push()?.setValue((array))
和
class CanvasView(context: Context, attrs:AttributeSet?): View(context,attrs) {
private var mAuth: FirebaseAuth
private var mFirebaseDatabase:FirebaseDatabase
var paint: Paint = Paint()
var path: Path = Path()
var apagar: Boolean = false
var array = arrayListOf<CustomPath>()
private var database: FirebaseDatabase? = null
private var myRefDraw: DatabaseReference? = null
var c = CustomPath(path,paint)
override fun onDraw(canvas: Canvas) {
for (p in array) {
canvas.drawPath(p.getPath(), p.getPaint())
}
super.onDraw(canvas)
}
fun clear(){
array.clear()
invalidate()
}
override fun onTouchEvent(event: MotionEvent): Boolean {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
path = Path()
path.moveTo(event.x, event.y)
c = CustomPath(path,paint)
array.add(c)
myRefDraw?.push()?.setValue((array))
}
MotionEvent.ACTION_MOVE -> {
path.lineTo(event.x, event.y)
invalidate()
}
MotionEvent.ACTION_UP -> {
}
}
return true
}
init {
paint.color = Color.BLACK
paint.style = Paint.Style.STROKE
paint.strokeWidth = 12f
paint.strokeJoin = Paint.Join.ROUND;
paint.strokeCap = Paint.Cap.ROUND;
mAuth = FirebaseAuth.getInstance();
mFirebaseDatabase = FirebaseDatabase.getInstance();
myRefDraw = mFirebaseDatabase.getReference("pathDraw");
}
}```