小编ica*_*bas的帖子

未解决的参考:junit

我正在使用Kotlin和LibGDX框架编写游戏。我是测试新手。我已经通过了一些有关如何创建简单测试的基本教程。以及如何配置gradle。我只是单击课程,然后选择创建测试。

但是,当我尝试构建项目时出现错误:

e: /Users/maximternovtsi/bagel/core/src/test/test/BagelTest.kt: (1, 12): Unresolved reference: junit
e: /Users/maximternovtsi/bagel/core/src/test/test/BagelTest.kt: (2, 12): Unresolved reference: junit
e: /Users/maximternovtsi/bagel/core/src/test/test/BagelTest.kt: (6, 6): Unresolved reference: Test
e: /Users/maximternovtsi/bagel/core/src/test/test/BagelTest.kt: (8, 9): Unresolved reference: Assertions
e: /Users/maximternovtsi/bagel/core/src/test/test/BagelTest.kt: (11, 6): Unresolved reference: Test
e: /Users/maximternovtsi/bagel/core/src/test/test/BagelTest.kt: (13, 9): Unresolved reference: Assertions

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':core:compileKotlin'.
Run Code Online (Sandbox Code Playgroud)

BagelTest看起来像这样:

import org.junit.jupiter.api.Test

import org.junit.jupiter.api.BeforeEach


internal class BagelTest {


    @BeforeEach
    internal fun setUp() {
    }

    @Test
    internal fun passes() {
        assert(true) …
Run Code Online (Sandbox Code Playgroud)

java junit gradle libgdx kotlin

6
推荐指数
2
解决办法
5199
查看次数

Kotlin + Maven 组装:没有主清单属性

我在使用 Maven 组装具有某些 JAR 文件依赖项的 Kotlin 项目时遇到问题。

我如何将项目组装到 JAR 中:

RightPanel -> MavenProjects -> Lifecycle -> package -> run
Run Code Online (Sandbox Code Playgroud)

当我运行 JAR 文件时:

java -jar path.jar
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

no main manifest attribute, in path.jar
Run Code Online (Sandbox Code Playgroud)

在这里maven-assembly-plugin添加了这样的内容:

所以我的插件目录如下所示:

<build>
    <sourceDirectory>src/main/kotlin</sourceDirectory>
    <testSourceDirectory>src/test/kotlin</testSourceDirectory>

    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals> <goal>single</goal> </goals>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>${main.class}</mainClass>
                            </manifest>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <version>${kotlin.version}</version>
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>test-compile</id>
                    <phase>test-compile</phase> …
Run Code Online (Sandbox Code Playgroud)

jar maven kotlin

4
推荐指数
1
解决办法
7171
查看次数

为什么我们在Kotlin中有名为componentN的函数

我刚看了Kotlin 标准库,发现了一些奇怪的扩展函数componentN ,其中N是从1到5的索引.

所有类型的基元都有函数.例如:

/**
* Returns 1st *element* from the collection.
*/
@kotlin.internal.InlineOnly
public inline operator fun IntArray.component1(): Int {
    return get(0)
}
Run Code Online (Sandbox Code Playgroud)

它对我来说很奇怪.我对开发者的动机很感兴趣.打电话array.component1() 而不是array[0]

arrays kotlin kotlin-extension

4
推荐指数
2
解决办法
165
查看次数

使用[]调用时出现奇怪的java.lang.ClassCastException

我正在为我的游戏使用LibDGX库.我遇到了常见的异常ClassCastException,但它发生在奇怪的情况下.

我正在使用LibGDX库中的Animation类.

只有在我使用操作时,我才会在此行上出错.[]

val tex = animation.keyFrames[0]
Run Code Online (Sandbox Code Playgroud)

如果我将其更改为get() 错误消失.

tex = animation.keyFrames.get(0)
Run Code Online (Sandbox Code Playgroud)

这是完整的方法.我简化了例子.

override fun create() {


    val frames = Array<TextureRegion>()
    frames.add(TextureRegion(Texture("badlogic.jpg")))

    val animation = Animation(frames)

    val tex1 = animation.keyFrames.get(0)  // Compiles

    val tex = animation.keyFrames[0]  // error - [Ljava.lang.Object; cannot be cast to [Lcom.badlogic.gdx.graphics.g2d.TextureRegion;


}
Run Code Online (Sandbox Code Playgroud)

奇怪,不是吗?

这是我用来最小化其他错误原因的Animation类.它与LibGDX api中的相同.

    public class Animation<T> {

    T[] keyFrames;
    private float frameDuration;


    public Animation (float frameDuration, Array<? extends T> keyFrames) {
        this.frameDuration = …
Run Code Online (Sandbox Code Playgroud)

java reflection libgdx kotlin

3
推荐指数
1
解决办法
399
查看次数

标签 统计

kotlin ×4

java ×2

libgdx ×2

arrays ×1

gradle ×1

jar ×1

junit ×1

kotlin-extension ×1

maven ×1

reflection ×1