我正在尝试构建一个圆组件,但遇到了奇怪的错误。 当我在设计模式下使用组件时,我可以看到绘制到视图的圆形组件,但我无法编译,因为出现以下错误。 欢迎所有帮助。谢谢
// drawable/circle.xml
<Circle
android:id="@+id/circle_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
// new package called Shapes.Circle.kt
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.PointF
import android.util.AttributeSet
import android.view.View
public class Circle @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
val paint = Paint().apply {
color = Color.RED
}
private val centre = PointF(50F, 50F)
override fun onDraw(canvas: Canvas?) {
canvas?.drawCircle(centre.x, centre.y, 50F, paint)
}
}
这是我的错误:
021-01-12 04:12:03.354 28620-28620/com.example E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example, PID: 28620
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.SplashScreen}: android.view.InflateException: Binary XML file line #12 in com.example:layout/activity_splash_screen: Binary XML file line #12 in com.example:layout/activity_splash_screen: Error inflating class Circle