im getting a compile error that i dont understand:...
# announcements
l
im getting a compile error that i dont understand:

https://i.imgur.com/6kNkSRr.png

it says "unresolved reference" even though in the editor it seems to be recognized just fine, it shows up in autocomplete and i can navigate to the implementation just fine. whats going on here?
s
Hi! I checked with the easiest sample and issue does not reproduce:
Copy code
import javax.sound.sampled.AudioInputStream

fun test(ais: AudioInputStream) {
    ais.readNBytes(ais.available()) // compiles fine
}
Can you send a code example?
l
I'll try to narrow it down
a
I see this happen in Android Studio on occasion and normally Invalidate and Restart does the trick.
l
Copy code
import <http://java.io|java.io>.ByteArrayInputStream
import <http://java.io|java.io>.ByteArrayOutputStream
import javax.sound.sampled.*
import kotlin.concurrent.thread

fun main() {
    val format = AudioFormat(
        192000f,
        16,
        1,
        true,
        true
    )
    val info = <http://DataLine.Info|DataLine.Info>(TargetDataLine::class.java, format)
    if (!AudioSystem.isLineSupported(info)) {
        error("Line not supported")
    }
    val line = AudioSystem.getLine(info) as TargetDataLine
    line.open(format)
    line.start()
    println("Start capturing...")

    val ais = AudioInputStream(line)
    val baos = ByteArrayOutputStream()
    var stop = false
    thread {
        Thread.sleep(3000)
        stop = true
    }
    while (!stop) {
        val buffer = ais.readNBytes(ais.available())
        //workaround: 
        //val buffer = ByteArray(ais.available())
        //ais.read(buffer)
        baos.write(buffer)
    }
    line.stop()
    line.close()
    println("done")
    val recorded = AudioInputStream(ByteArrayInputStream(baos.toByteArray()), format, baos.size().toLong())


    readLine()

    val clip = AudioSystem.getClip()
    clip.open(recorded)
    clip.start()
}
records 3 seconds audio, then plays it back after pressing enter. i found a workaround but i'd still like to understand the error
IDE restart or gradle-reimport didnt fix it
s
Build is successful for this example in my case.
Are you getting a compile error?
l
all i get is whats shown on the screenshot
s
can you share your build.gradle?
l
Copy code
plugins {
    kotlin("jvm") version "1.3.61"
}

group = "lastexceed"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    implementation(kotlin("stdlib-jdk8"))
    compile(files("src/main/resources/jnativehook-2.1.0.jar"))
}

tasks {
    compileKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
    compileTestKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
}
s
Still unable to reproduce. Seems to be some sporadic bug. Can you attach your project?
l
alright sec
KeyboardMouseTester.zip
j
Could it be a java version issue? readNBytes was only introduced in Java 9.
l
i use 13.0.1
s
It compiles fine at my site. Did you try
Shift+Shift -> Invalidate Caches / Restart...
?
l
not yet, gonna try that now
didn't help
s
Ok, lets go on. 😃 Attach please "File -> Export Settings...". And I'll try to compile with Java 13.0.1
l
there is no "export settings" option for me

https://i.imgur.com/QxiS4wB.png

or am i blind?
s
just a sec
l
ah yes thats probably it
🆒 1
how do i disable it?
nvm found it
settings.zip
s
Compiles fine with Oracke JDK 13.0.1
Problem seems to be with AdoptOpenJDK
l
were you able to reproduce?
with AdpotOpenJDK i mean
s
not yet. downloading it now
Also compiled successfully
l
(╯°□°)╯︵ ┻━┻
s
The only difference I see now is My AdoptOpenJDK installation folder named jdk-13.0.1.9-hotspot and yours is jdk-13.0.1+9
Can you try to re-compile this code with different jdk?
l
i can, which should i use?
s
e.q. one by Oracle
Also what is your Windows version?
And Idea version (Help -> About)?
l
windowsVersion 10.0.18363 Build 18363
IDEA 2019.3 build 193.5233.102
btw is it normal that it says
Copy code
implementation(kotlin("stdlib-jdk8"))
and
Copy code
kotlinOptions.jvmTarget = "1.8"
in the build.gradle even though the project jdk is 1.13 and not 1.8 ? (not that familiar with this stuff)
s
It is correct. Don't remember why exactly but this it what should be there
l
installed OracleJDK 13.01 now, problem persists
l
Try deleting the .idea folder
When this kiind of thing happens I just delete
.idea
and
Invalidate/Restart
l
done, didnt help
s
@LastExceed did you also tried to delete
.idea
folder?
l
yes thats what i just tried
s
I can suggest to create a new project and try to do all the same in it. It is definitely some configurational bug.
l
done, didnt help
i created a new project and just pasted the same code from above in it, same error
s
magic
@Alexey Belkov [JB] do you have any idea?
🤷 1
@LastExceed did it help to compile with different JDK?
l
no
s
What is the second error message is there?
l
i think that was unrelated (when i was still working on the whole project), i dont have that second error now
s
@LastExceed If your problem still actual I suggest you to check the same name resolution in Java. In case it does not resolve in Java (actually in any case) I would recommend you to ask IDEA support. They have more experience in such a weird problems.
l
ayy, we're making progress: i re-implemented the code sample in java and now it highlights and error in the editor:
Usage of API documented as @since 11+
which is strange because my project language level is set to 13 (and setting it to 11 doesn't solve it either). HOWEVER the IDE still gave me the suggestion "set language level to 11" and clicking that solved the problem, but I am now oblivious to what was actually the problem since as i said the the project language level was already high enough and I am now unable to reproduce the error anymore even if i create a whole new project like before. I'd really like to understand what's going on here especially since there is definitely something on the Kotlin side that needs to be fixed, can you explain? @Sergei Dubrov [JB]
s
Please report a ticket for false positive inspection at https://youtrack.jetbrains.com/issues/IDEA? Regarding the problem with resolve in Kotlin, it is not clear how it can be reproduced. It could also be an IDEA bug. In case you find a way how to do that please report it at https://youtrack.jetbrains.com/issues/KT?.