I'm currently, in my layout "activity_main.xml" defining a variable as
android:id="#+id/viewPager"
without any error. later on - I tried to reference this variable in MainActivity with:
viewPager.adapter = adapter
At this point an error is thrown "unresolved reference: viewPager"
Not sure why viewPager isn't being recognized.
Its my first day on Android Studio - sorry for my ignorance.
Related
Recently I've installed the Bumblebee version of Android Studio and I've remarked strange new fields marked with p icon and ...get() in my debugger variables pane.
I haven't found any info about these fields, so maybe you can answer? They are so annoying, just duplicating info about val fields in the class.
See the screenshots and the sample class:
data class MyOwnClass2(
val fieldOne: String,
val fieldTwo: Int,
)
I'm using coroutines in the app, and have some Java code mixed with Kotlin one.
I can only imagine that these fields are 'properties' of the class, but I didn't explicitly override custom get/set.
TL;TR: #JvmField or migrate from Java!
So after all, these are consequences of using both Kotlin and Java code in the same module. When I put #JvmField, it doesn't generate these get/set in Kotlin, so no 'p' fields in the debugger are seen any longer.
Building of my android app failed with a new strange set of errors:
theapp/app/build/generated/data_binding_base_class_source_out/debug/out/com/comTest/theapp/databinding/TabPinBinding.java:48: error: illegal '.'
public final com.comTest.theapp..utilsviews.MyTextView pin8;
The class MyTextView is defined in theapp/utils/views/MyTextView.kt
it looks like the generator of java code makes a mistake.
As this code is right in generated java, I don't know how to correct the error or where to begin with to fix the problem.
The application compiled fine then I did the following:
created a scratch.kt file where I needed to import some file defined in the utils folder
updated some stuff (gradle pluggin, targetSDK value, remove redundant dependencies) following suggestion of android-studio. It was the usual stuff when updating android-studio internals.
the errors appear in the file TabPinBinding.java which start with:
"// Generated by view binder compiler. Do not edit!"
I find the error.
It comes from a layout not used anymore in the project.
<?xml version="1.0" encoding="utf-8"?>
<com.comTest.theapp..utilsviews.PinTab
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pin_lock_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.comTest.theapp..utilsviews.MyTextView
android:id="#+id/pin_lock_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/small_margin"
android:paddingLeft="#dimen/activity_margin"
android:paddingRight="#dimen/activity_margin"
android:paddingTop="#dimen/activity_margin"
android:text="#string/enter_pin"/>
<!-- other fields -->
</com.comTest.theapp..utilsviews.PinTab>
I do not know why the layout uses a wrong path to access the Layout class defined in the project but I suspect a bug of the IDE when propagating changes related to renaming or moving of the Layout class file.
This change was made a long time ago, and gradle and android studio seemed to have ignored the problem so far. Why it pops up now ?
I have updated the kotlin version to Java 8 (sourceCompatibility "1.83) and other changes. It looks that many problems are poping up...
To find the problem I made a search on the entire project with the string com.comTest.theapp..utilsviews
To remove the problem, I corrected the paths in the layout to : com.comTest.theapp.utils.views wherever the error occured.
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?
So, I have been trying to migrate the development of a multi-project (eclipse projects that is) app to Android Studio (v1.1).
Importing via File > Import Project was really easy and went without incident.
However, when I tried Make/Rebuild project I encountered numerous surprises. The first, not Proguard-related, had to do with source file encoding (originally in Windows-1252), but I quickly found a solution using this Windows-1252 > Reload > UTF-8 > Convert answer.
Then, "error: cannot find symbol class" for a com.comp.mod.X class of mine. I then solved it by going to the module (Android Studio module that is, previously an Eclipse project) that contains that class and added to its proguard.cfg the following:
-keep public class com.comp.mod.X
Which left me with an "error: cannot find symbol variable" for a const BB defined in the aforementioned class. I solved this by adding to the same proguard.cfg the following:
-keepclassmembers class com.comp.mod.X {
public static final boolean BB;
}
That left me with only one "error: cannot find symbol method getPreferenceX()". I solve this by adding to the same -keepclassmembers that method, so that the above now looks:
-keepclassmembers class com.comp.mod.X {
public static final boolean BB;
public static java.lang.String getPreferenceX();
}
I thought I was done, but to my dismay, when I attempted to rebuild the project, I received numerous additional errors from other modules in the project, all of the type to "error: cannot find symbol class/variable/method" and related to some proguard.cfg.
I could have continued butchering the proguard.cfg files for each and every module but at this point I am beginning to suspect that I am doing something fundamentally wrong, because those proguard.cfg files work perfectly under Eclipse. So,
Why all of a sudden these are no longer good for Android Studio?
If ProGuard runs only when you build your application in release mode, why is the Android Studio based build complaining about "cannot find symbol" due to Proguard's obfuscation?
What am I missing?
Note: I have not attempted "Generate Signed APK". All I do is "Rebuild Project".
Currently (as of 2015-04-24), minifyEnabled's default value of false for all build types is incorrect for multi-module projects, in which some modules (app included) are dependent on other modules. This is due to bug #52962 that causes build types to not propagate to libraries -- they are always built as RELEASE.
Suggestions to work around this bug or notifications of its fix are most welcome.
I created a new Android project via eclipse, with a MainActivity.
I added ActionBarSherlock to the project (Properties > Android and clicked Add).
Then, when I replace "extends Activity" with "extends SherlockFragmentActivity" I get a compile error "The hierarchy of the type MainActivity is inconsistent".
I also tried to create a project without an Activity, then created a class "MainActivity" that inherits from SherlockFragmentActivity, and there are no compile time errors, but with a run-time error "ClassNotfoundException: com.NadavLitvak.nadavfragmentdemo.MainActivity"
Your project should also reference the android-support-v4.jar (which is included in ABS's libs folder.) So, Properties->Java Build Path->Add JARs... and select that jar from ActionBarSherlock->libs
Sometimes, when Eclipse gets retarded, it doesnt add the SDK jar in your project (the Android x.y folder missing in project) so then you need to add it Properties > Android > Project Build Target (usually nothing there is ticked)