- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个自定义属性,专门用于保存我的一个项目需要 invalidate() 调用的 View 属性:
class InvalidatingProperty<T>(private var _value: T) {
operator fun getValue(thisRef: View, property: KProperty<*>): T {
return _value
}
operator fun setValue(thisRef: View, property: KProperty<*>, value: T) {
_value = value
thisRef.invalidate()
}
}
在另一个项目中,我想重用我以前的一些工作,所以我将 View 及其依赖项(包括 InvalidatingProperty)复制到一个新项目中。但是在新项目中,使用 InvalidatingProperty 会导致预览渲染失败,并出现以下异常:
java.lang.NoSuchMethodError: kotlin.jvm.internal.MutablePropertyReference1Impl.<init>(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
at com.gradesimulator.views.SummaryView.<clinit>(SummaryView.kt)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:403)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:186)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:144)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:309)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:416)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:427)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:331)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1123)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1097)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:501)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:348)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:404)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:678)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$8(RenderTask.java:809)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
源项目(预览工作的地方)和目标项目,都有相同的 android 版本 - 4.0.1,使用相同版本的 kotlin 和 kotlin gradle 插件 - 1.4.0
java.lang.NoClassDefFoundError: Could not initialize class com.gradesimulator.views.SummaryView
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:403)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:186)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:144)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:309)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:416)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:427)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:331)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1123)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1097)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:501)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:348)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:404)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:678)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$8(RenderTask.java:809)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
压缩摘要查看代码:
@Suppress("MemberVisibilityCanBePrivate", "unused", "PropertyName")
class SummaryView : View {
companion object {
private const val TAG = "SummaryView"
//primary circle
const val DEFAULT_PRIMARY_CIRCLE_RADIUS_SCALE: Float = 1F
const val DEFAULT_PRIMARY_CIRCLE_DISPLACEMENT: Float = 0.3F
//secondary circle
const val DEFAULT_SECONDARY_CIRCLE_RADIUS_SCALE: Float = 1F
const val DEFAULT_ANIMATE_IN_SECONDARY_CIRCLE_DELAY: Long = 100
const val DEFAULT_SECONDARY_CIRCLE_DISPLACEMENT: Float = 0.2F
//both circles
const val DEFAULT_CIRCLES_SHADOW_RADIUS: Float = 0F
const val DEFAULT_CIRCLES_SHADOW_DISPLACEMENT: Float = 0F
const val DEFAULT_ANIMATE_IN_CIRCLES_ANIMATION_DURATION: Long = 600
//bigAverage
const val DEFAULT_BIG_AVERAGE_SHADOW_DISPLACEMENT_X: Float = 0F
const val DEFAULT_BIG_AVERAGE_SHADOW_DISPLACEMENT_Y: Float = 0F
const val DEFAULT_BIG_AVERAGE_SHADOW_RADIUS: Float = 0F
//smallAverage
const val DEFAULT_SMALL_AVERAGE_SHADOW_DISPLACEMENT_X: Float = 0F
const val DEFAULT_SMALL_AVERAGE_SHADOW_DISPLACEMENT_Y: Float = 0F
const val DEFAULT_SMALL_AVERAGE_SHADOW_RADIUS: Float = 0F
//average
const val DEFAULT_AVERAGE_MARGIN: Float = 0.4F
//progressArc
const val DEFAULT_ANIMATE_IN_PROGRESS_ARC_ANIMATION_DURATION: Long = 1200
const val DEFAULT_PROGRESS_ARC_MARGIN: Float = 0.2F
const val DEFAULT_PROGRESS_ARC_WIDTH: Float = 0.1F
const val DEFAULT_PROGRESS_ARC_START_ANGLE: Float = 10F
const val DEFAULT_PROGRESS_ARC_VALUE: Float = 0.96F
//progressArcDot
const val DEFAULT_PROGRESS_ARC_DOT_RADIUS: Float = 1.5F
//progressArcContent
const val PROGRESS_ARC_CONTENT_DEFAULT_MARGIN = 0.4F
const val DEFAULT_PROGRESS_ARC_CONTENT_TEXT = "Of the success!"
const val DEFAULT_PROGRESS_ARC_CONTENT_INTERLINE = 0.1F
const val PARTICLE_DATA_REGEX = ";"
}
//primaryCircle
val DEFAULT_PRIMARY_CIRCLE_COLOR: Int = Color.GRAY
//SecondaryCircle
val DEFAULT_SECONDARY_CIRCLE_COLOR: Int = Color.DKGRAY
//Both circles
val DEFAULT_CIRCLES_SHADOW_COLOR: Int = Color.BLACK
//bigAverage
val DEFAULT_BIG_AVERAGE_SHADOW_COLOR: Int = Color.BLACK
//smallAverage
val DEFAULT_SMALL_AVERAGE_SHADOW_COLOR: Int = Color.BLACK
//Averages
val DEFAULT_AVERAGE_COLOR: Int = Color.WHITE
//progressArc
val DEFAULT_PROGRESS_ARC_COLOR: Int = Color.WHITE
//progressArcDot
val PROGRESS_ARC_DOT_DEFAULT_COLOR = Color.WHITE
//progressArcContent
val DEFAULT_PROGRESS_ARC_CONTENT_COLOR = Color.WHITE
//particles
val DEFAULT_PARTICLE_COLOR = Color.DKGRAY
//View
var animateInCirclesAnimationDuration = DEFAULT_ANIMATE_IN_CIRCLES_ANIMATION_DURATION
var animateInProgressArcAnimationDuration = DEFAULT_ANIMATE_IN_PROGRESS_ARC_ANIMATION_DURATION
var animateInSecondaryCircleDelay = DEFAULT_ANIMATE_IN_SECONDARY_CIRCLE_DELAY
//Circles
private val primaryCirclePaint: Paint = Paint()
private val secondaryCirclePaint: Paint = Paint()
var primaryCircleCenterDisplacement: Float by InvalidatingProperty(
DEFAULT_PRIMARY_CIRCLE_DISPLACEMENT
)
var secondaryCircleCenterDisplacement: Float by InvalidatingProperty(
DEFAULT_SECONDARY_CIRCLE_DISPLACEMENT
)
var primaryCircleColor: Int
set(value) {
primaryCirclePaint.color = value
invalidate()
}
get() = primaryCirclePaint.color
var secondaryCircleColor: Int
set(value) {
secondaryCirclePaint.color = value
invalidate()
}
get() = secondaryCirclePaint.color
var primaryCircleRadiusSCale: Float by InvalidatingProperty(1F)
var secondaryCircleRadiusScale: Float by InvalidatingProperty(1F)
fun setCirclesShadow(radius: Float, dx: Float, dy: Float, color: Int) {
primaryCirclePaint.setShadowLayer(radius, dx, dy, color)
secondaryCirclePaint.setShadowLayer(radius, dx, dy, color)
}
fun setBigAverageShadow(radius: Float, dx: Float, dy: Float, color: Int) =
bigAveragePaint.setShadowLayer(radius, dx, dy, color)
fun setSmallAverageShadow(radius: Float, dx: Float, dy: Float, color: Int) =
smallAveragePaint.setShadowLayer(radius, dx, dy, color)
//Big Average
private val bigAveragePaint: TextPaint = TextPaint()
var bigAverageText: String by InvalidatingProperty("")
//SmallAverage
private val smallAveragePaint: TextPaint = TextPaint()
var smallAverageText: String by InvalidatingProperty("")
//Both averages
var averageMargin: Float by InvalidatingProperty(DEFAULT_AVERAGE_MARGIN)
var averageColor: Int
get() = bigAveragePaint.color
set(value) {
bigAveragePaint.color = value
smallAveragePaint.color = value
invalidate()
}
//Progress Arc
private val progressArcPaint: Paint = Paint()
var progressArcMargin: Float by InvalidatingProperty(DEFAULT_PROGRESS_ARC_MARGIN)
var progressArcStrokeWidth: Float by InvalidatingProperty(DEFAULT_PROGRESS_ARC_WIDTH)
var progressArcStartAngle: Float by InvalidatingProperty(DEFAULT_PROGRESS_ARC_START_ANGLE)
var progressArcValue: Float by InvalidatingProperty(DEFAULT_PROGRESS_ARC_VALUE)
private val progressArcRectF: RectF = RectF()
//ProgressArcDot
private val progressArcDotPaint = Paint()
var progressArcDotRadius: Float by InvalidatingProperty(DEFAULT_PROGRESS_ARC_DOT_RADIUS)
//Progress Arc Content
private val progressArcContentPaint: TextPaint = TextPaint()
val progressArcContentMargin: Float by InvalidatingProperty(PROGRESS_ARC_CONTENT_DEFAULT_MARGIN)
var progressArcContentColor: Int
set(value) {
progressArcContentPaint.color = value
invalidate()
}
get() = progressArcContentPaint.color
var progressArcContentText: String by InvalidatingProperty(DEFAULT_PROGRESS_ARC_CONTENT_TEXT)
var progressArcContentTextInterline: Float by InvalidatingProperty(
DEFAULT_PROGRESS_ARC_CONTENT_INTERLINE
)
//Particles
private val particlePaint: Paint = Paint()
private val particles: ParticleSet =
ParticleSet(this)
var particlesColor: Int
set(value) {
particlePaint.color = value
invalidate()
}
get() = particlePaint.color
//Util
private val textBoundsRect: Rect = Rect()
private val textBoundsRect2: Rect = Rect()
constructor(context: Context?) : super(context) {
initView(null)
}
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
initView(attrs)
}
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
) {
initView(attrs)
}
constructor(
context: Context?,
attrs: AttributeSet?,
defStyleAttr: Int,
defStyleRes: Int
) : super(context, attrs, defStyleAttr, defStyleRes) {
initView(attrs)
}
private fun initView(attrs: AttributeSet?) { //code }
override fun onDraw(canvas: Canvas?) { // code }
最佳答案
将 kotlin-reflect 版本从 1.4.0 更改为 1.3.72 对我有用:
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.72"
关于android - Kotlin 委托(delegate)属性导致 Android Studio 中出现预览渲染错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63474372/
我有一个加载 View 的 View ,需要将 View 推送到主导航 Controller 。 我已经为每个 View 设置了一个委托(delegate),并且基本上使我的调用沿着“链”返回到主导航
我通过 NSURLConnction 从服务器获取数据,并希望从获取的数组中填充表格 View 。数据出现在 NSURLConnection 委托(delegate)方法的日志中,但我意识到 numb
我已经将我用作标题 View 的 View 子类化,它里面有一些按钮委托(delegate),它工作得很好。 但是,我在 viewController 上方展示了一个 modalViewControl
我希望这听起来像是一个显而易见的问题,但是委托(delegate)返回类型是否也必须与其委托(delegate)的方法的返回类型相匹配? EG,像这样: public static void Save
我想使用 Kotlin 委托(delegate),但我不想在委托(delegate)人之外创建委托(delegate)。委托(delegate)的所有示例都如下所示: interface Worker
我有一个问题: - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInf
伙计们。我正在寻求帮助。这似乎是一个非常简单的任务,但我可以解决一整天。我正在尝试使用容器 View 创建侧面菜单。当用户按下“更多”按钮(barButtonItem)时,整个 View 向右滑动并出
我正在努力将 UIWebView 迁移到 WKWebView。我已经更改了所有委托(delegate)方法。我需要 WKWebView 委托(delegate)方法等于下面的 UIWebView 委托
我正在学习 VB.NET 中的委托(delegate),但对委托(delegate)类型感到困惑。在阅读有关委托(delegate)的内容时,我了解到委托(delegate)是一种数据类型,可以引用具
我有一个用 Objetive-C 构建的框架。该框架用于连接蓝牙设备并与之交互。 在演示代码中,Objetive-C 委托(delegate)函数如下所示。演示代码由框架创建者提供。 -(void)b
//NewCharts.h #import @interface NewCharts : UIViewController @property(nonatomic,retain)IBOutlet U
我正在努力了解 async/await 并认为我确实了解有关用法的一些事情。但仍然不太清楚在下面的场景中实际好处是什么。 查看 Task.Run 用法。第一种方法使用普通委托(delegate)并使用
我已经尝试了在我的网站上使用 openID 委托(delegate)的所有可能选项,但没有一个方法对我有用。 我的 HTML 文件的 head 部分有“link rel”标签。 我在 HTML 文件的
如何快速创建一个委托(delegate),即 NSUserNotificationCenterDelegate? 最佳答案 这里有一些关于两个 View Controller 之间委托(delegat
我有一个带有数据源的 NSComboBox,当您单击三角形并通过单击它选择其中一个项目时,它可以完美运行。但是,我还希望它允许用户在框中键入以使用自动完成来选择名称。目前,当用户键入时,我希望选择的项
我在代码中定义了以下类和委托(delegate)(为简洁起见,剪掉了许多其他行)。 Public Delegate Sub TimerCallback(canceled As Boolean) Pub
我使用 ansible 2.1 并且我想使用 delegate_to 向一组主机运行命令。我使用 localhost 作为主机参数,并且我想将“touch”命令委托(delegate)给两个 cls
我想通过重载为我的类实现几个构造函数。据我了解,遵循 DRY 原则的惯用方式是使用一种称为委托(delegate)构造函数的功能。我也看到了关于在任何地方使用引用参数并不惜一切代价避免使用指针的想法,
代表们会导致内存泄漏吗? 我的意思是,例如如果一个类A包含一个ADelegate,并且后者指向BMethod(属于B类),这可以防止GC收集A类或B类吗? 如果是这样,我们如何“释放”代表(设置ADe
委托(delegate)命令和路由命令有什么区别? 我读了一些文章说在 MVVM 上使用委托(delegate)命令而不是路由命令。 那么当我们使用 MVVM 时,Delegate Command 相
我是一名优秀的程序员,十分优秀!