Android studio problem with configuration: type mismatach problem - android-studio

I wrote a code like that:
var btn: Button = view.findViewById(R.id.btn)
view.findViewById(R.id.btn) is red underlined.
It's working fine but Android studio tolds me that it is mismatch type (Compiler expected View!). It had been working fine until i changed a profile from debug to release. Since that it show me errors.
And one more error which i recived is with:
view.findViewById<TextView>(R.id.user_name)
TextView is red underlined.
No type args expected for fun.
I belive that error s only becouse of android studio config. I can compile my code witout any problem, but android studio doesn't suggest me things like that.
Have you maybe any suggests ?

Have you tried to rebuild and clean your code? #Young_User
Might be an issue with what you are inheriting in your class.
Care to share the error code and full class too?

Related

Why is my android studio kotlin plugin version in different format than my co-workers?

I stumbled into an issue where all my unit test classes fail to run, providing the following error:
java.lang.IllegalStateException: Failed to transform class with name <my class name>. Reason: toPrettyPrint (Ljava/lang/String;)Ljava/lang/String; in <my class name>: inconsistent stack height -1
One user commented on the following github thread for powermock, that the same error first happened to them after updating their kotlin plugin:
https://github.com/powermock/powermock/issues/779
After reading this, I have checked with my colleagues to see maybe they have a different kotlin version, and saw that their kotlin plugin version is
203.1.6.0-release-798-AS7717.8, whereas mine is 1.4.32-release-Studio4.1-1.
What I find peculiar abbout this, is that these versions dont follow the same conventions, they look more like two completely different sofware. Is there any way for me to get the same version for my kotlin plugin ?
Any help or clarification is much appreciated, thanks!
They probably just changed the naming scheme for the plugin. Looks like you have one that is about one and a half years out of date.
Anyway, go to File -> Settings -> Languages & Frameworks -> Kotlin and click the Install button.

Why happens this weird compiler behaviour in Android Studio 3.6?

I've updated for Android Studio 3.6 today (#AI-192.7142.36.36.6200805, built on February 12, 2020). I use Kotlin (my version - 1.3.61 - is updated). My Gradle version is 5.6.4(the last one).
A very strange stuff is happening for me.
The first problem is that now I need to press save icon (^s) before running. Until Android 3.5 was automatic. But it's Ok, it is a matter of getting used to it.
The second problem is worst. I have a typealias that was ArrayList and I needed change to a simple Array, so I've changed the previous code typealias Duo = ArrayList<Double> for typealias Duo = Array<Double>.
It's a big project, and I have in some module a small piece of code, that can be shown as
var gData = ArrayList<Duo>()
gData.add(arrayOf(5.0, 1.0))
after I've saved the files (^s) and run.
Now appears the below error message pointing to the second line, even if the editor don't show a red mark in the code:
Type inference failed. Expected type mismatch: inferred type is Array<Double>
but Duo /* = ArrayList<Double> */ was expected
I have no clue what is happening.... I've tried to restart and restart and invalidate caches, with no success. The same messages. I use find in path (^+f) to check duplicate declarations of duo. Nope.
When I've tried the below toy code in Kotlin Playground, it's OK. No error.
typealias Duo = Array<Double>
fun main() {
var gData = ArrayList<Duo>()
gData.add(arrayOf(5.0, 1.0))
println(gData[0][0])
}
I'm lost!
UPDATE
It should be a very serious bug in Android Studio 3.6.
I've solved the problem, but it doesn't make any sense. I simply have replaced all 13 occurrences of duo with dux and the problem is over! (Ctrl + Shift + R - Replace in Path) After, I've switched back for duo (13 occurences) and the problem didn't return, but the mystery is on the air.

Android Studio Kotlin databinding: Unresolved reference on BR

I have some code that is generating a "red squiggly" error in Android Studio:
#get:Bindable
var title: String = ""
set(value) {
field = value
notifyPropertyChanged(BR.title)
}
It complains that "title" is an unresolved reference on BR.title. Building and running works fine though, and this is the only error I can see. I debug there and see that it's gotten the value for BR.title correctly.
Still, I can't figure out how to make it go away. I verified that the generated BR class has the "title" field, but Android Studio refuses to recognize this. I've looked up people having this issue and have tried the following: (unsuccessfully)
Closing Android Studio, deleting the .gradle, .idea and build folders and restarting
Build -> Clean Project, Rebuild Project
File -> Invalidate Caches and restart
Disabling and enabling the Kotlin plugin
Closing and reopening the project
I have also checked and I have apply plugin: 'kotlin-kapt' in build.gradle.
Anyone know what's going on? I assume it must be holding onto some cache files somewhere but I don't know where.
What fixed the problem for me was adding the following import to my files:
import androidx.databinding.library.baseAdapters.BR
I'm not entirely certain why this works, but it got rid of all the analysis problems and the application still compiles and works fine, so I'm personally happy.

cocos2d-x for android, crash with string concatenation

On Cocos2d-x v3 this code:
string _nameImgBase="pedina";
string nameImg=_nameImgBase+"B.png";
auto img=Sprite::createWithSpriteFrameName(nameImg);
compiles without errors, but on Android crash the application.
The strange thing is that if I compile the same code on XCode for iPhone ... then there are no problems, everything is working.
Why?
It's probably not present in the "SpriteFrameCache",but if you want to add a simple sprite from your resources folder you simply use
auto img=Sprite::create(nameImg);

Typescript giving "Output Generation Failed" in Visual Studio 2012 with 0.9.5

I've been using Typescript 0.9.5 for the last few days, and then suddenly today the JavaScript files just stopped being generated. I see an error "Output generation failed" in the Visual Studio status bar, but nothing in any of the output windows.
I've rebooted, and restarted Visual Studio, disabled Web Essentials, tried all the usual things.
The files are set as TypescriptCompile in the properties. I've tried adding new files, or editing old ones with no effect. The Project file hasn't been changed as far as I can tell (its in TFS and none of the TypeScript sections have been altered).
I've made sure both files are checked out, still nothing.
Update: I've managed to compile manually using tsc.exe from the command line, so it must be something in Visual Studio.
OK, so I solved the problem.
One of my files contained invalid typescript, specifically trying to export a class when not inside a module. This caused all typescript files to fail to generate, but with no useful error message.
The following file would cause the problem:
export class Test {
public DoSomething() {
}
}
Either removing the export keyword, or adding a wrapping module solved the problem.
I've raised it as an issue here: https://typescript.codeplex.com/workitem/2109
Update: More details.
The above syntax is valid if you are using the CommonJS or AMD module patterns.
To enable this in visual studio you need to edit the .csproj file and insert a new PropertyGroup:
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
If you have an export outside of an internal module Typescript tries to compile it as either commonjs or amd module format. The compilation will fail if the a --module flag is not present on the command line. Use your project properties to set it to the desired value (probably amd in your case).
More info on TypeScript modules : http://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1

Resources