String encoding in class library project - android

I am facing a strange problem.
I have a solution that contains an Android project and a class library project.
If in that library project I execute this line:
String s = "Código inválido";
This is actually shown when watching the variable: Código inválido.
However, when I do that assignment inside the Activity code, the text is shown correctly as Código inválido.
What may be wrong with this?
The origin of the problem was when I tried to show, in the Activity layout, a text that was assigned in a class library method. After a lot of digging, I found what I expose in this question.
Just in case, I tell you that all files encodings are UTF-8, and in the project settings all encodings are also UTF-8.
This is Android Studio 4.0.1
Thanks
Jaime

Related

Android Studio not recognizing Espresso/Hamcrest static method names without prefacing with the classname

I wasn't sure exactly what headline to give this question because I'm not sure what this is technically called. In Android Studio while typing out Espresso tests I noticed that it refuses to accept something like this:
onView(withId(R.id.someId)).perform(click());
and instead will only accept this:
Espresso.onView(ViewMatchers.withId(R.id.someId)).perform(ViewActions.click());
even though every example that I've seen online shows the first example as correct code. Why is Android Studio forcing me to preface every ViewMatcher/Espresso/ViewActions/etc. method with the classname even after the imports are included in my class?
To clarify - trying to use the first example shows "cannot resolve method" and using autocomplete on it (which I have to do several times before it will work) invariably autocompletes to the second example. In all the "regular" code for my project autocomplete works correctly and short method names are recognized. I've tried doing a "clean" and "invalidate cache and restart" but no change.
Example of Google doc that shows usage according to the shortened code:
https://developer.android.com/training/testing/ui-testing/espresso-testing.html
You can try to check out your Android Studio Preferences for imports. Just go to Preferences -> Search "imports"
Here are the settings that I use and I don't have that issue:
What fixed the issue for me: just removed red withId in one place. Then just re-entered "withId": after that all the other red withId were replaced with black text color withId and now it compiled successfull!

Hello world android - creation with errors

I'm trying to create my first app with Android but I've encountered some problems.
Following a tutorial and making:
new android application -> blank activity
The default result should be:
With MainActivity.java and R.Java inside it.
But instead I've got this:
There are a lot of errors and the R.Java file is missing.
I can obtain a result similar to the tutorial one (with no errors), creating a new android application and unchecking create activity, but this time MainActivity.java under src is totally missing.
Maybe I could copy the MainActivity.java of the first project and put into the second one, but I prefer understand why it doesn't work.
Thanks for the help.
Best regards.
its import library problem
Right click on you application----->Android
under library view ,
check if you have this red error then remove the library and add it again

Import android-support-v7-appcompat within a library project causes: R cannot be resolved to a variable

I have an Android project in which I want to generate two versions, one paid and one with advertising. According read on Stackoverflow, one way to do this is to create a parent project and create 2 child projects who imported the parent as a library. Also I use appcompat, so the hierarchy is as follows:
The problem is that the R class does not compile due to an error, which I can not find. But when the parent project did not configure as library ("Is library unchecked") everything works fine. Here the pictures:
Hopefully you can help me, thanks in advance.
Edit: mark's answer resolved the problem with android.support.v7.appcompat.R.id.search_src_text, but I still have errors with the R class, example:
Sorry for my English.
Replace the error line with this:
EditText editText = (EditText) searchView.findViewById(R.id.search_src_text);
I found the problem. In fact, mark's answer solved part of the errors, but, after reading this post Resource ID In Android Library Project, solved the problem with menu id's.
Thanks.

Multiple library projects in aide?

I am trying to work on my android app from my phone and tablet using Aide. I keep getting hundreds of errors. It seems as if it is only detecting one library project at a time. I can change which errors I get by removing a library and adding a different one (I am using three)
Has anyone successfully used multiple project libraries in aide, and might be able to offer some assistance?
My project . properties looks like this:
[Eclipse references (I think)]
android.library.reference.1=../../../../libraries/android-greendroid/GreenDroid
android.library.reference.2=../../../../libraries/ActionBarSherlock/library
[Aide references]
android.library.reference.1=/storage/extSdCard/code/android-actionbarsherlock/library
android.library.reference.1=/storage/extSdCard/code/android-facebook/facebook
android.library.reference.1=/storage/extSdCard/code/android-greendroid/GreenDroid
android.library.reference.1=/storage/extSdCard/code/android-actionbarsherlock/library
android.library.reference.1=/storage/extSdCard/code/myproject/android/free
So, the aide references are all .1 and there are no new lines between them.
I also had the same problem and fix this formating references like in eclipse.
Like this:
[Eclipse references]
android.library.reference.1=../../../../libraries/android-greendroid/GreenDroid
android.library.reference.2=../../../../libraries/ActionBarSherlock/library
[Aide references]
android.library.reference.1=/storage/extSdCard/code/android-actionbarsherlock/library
android.library.reference.2=/storage/extSdCard/code/android-facebook/facebook
android.library.reference.3=/storage/extSdCard/code/android-greendroid/GreenDroid
android.library.reference.4=/storage/extSdCard/code/android-actionbarsherlock/library
android.library.reference.5=/storage/extSdCard/code/myproject/android/free
You can't edit project.properties in AIDE, so use text edit and fix this. Put enter in right place and fix reference number ;)

Type R is already defined error

How do I fix this? I already tried removing the R.java and cleaning the project via eclipse, but it doesn't help.
FYI I am trying to get PhotoStream from here: http://code.google.com/p/apps-for-android/, but so far it has been very difficult to get things work.
Okay..... 5 mins later google tells me the correct answer...
http://www.fairtec.at/en/it-blog-mainmenu-16/168-the-type-r-is-already-defined
I just didnt search hard enough.
"The type R is already defined"
That's the message you get in Eclipse if you try to build the Funambol Android Sync Client.
Reason is that you have checked two Builders that try to generate the same class.
You just have to uncheck the Java-Builder from Project->Properties->Builders.
Then the application even works fine in the Emulator.
Delete the R.java from the src folder and rebuild the project. This file will be automatically rebuit during this process.
http://www.fairtec.at/en/it-blog-mainmenu-16/168-the-type-r-is-already-defined
click right to project click properties
Project->Properties->Builders.
unckeck java Builder
delete file R.java
You may want to change your package names. It looks like you are using a 'PhotoStream'.jar which has it's R.class defined at the same package structure as you.
Here is a link to the R.java from the project on Google Code. Notice you are using the same package:
http://code.google.com/p/apps-for-android/source/browse/trunk/Photostream/src/com/google/android/photostream/R.java?r=83
I had the same issue when I imported a project from work. Turning off the Java builder as suggested in the article you found fixed my problem, but when I made code updates they were not reflected in the running app. In my case there was an R.java in my source which I deleted and that fixed my problem.
In my case,
as i m not using any IDE for programming but using command line Android..
i had two xml files, one in layout and other in layout-land. i was using same id "XXX" for both but while declaring i made small mistake
android:id="#+id/XXX" (in layout xml)
android:id="#+id/XXX " (in layout-land xml)
please observe extra space in second id declaration, so while creating R.java they were different and in R.java i had
public static final int XXX=0x7f040046;
public static final int XXX =0x7f040045;
which are same, so please be aware of extra spaces. Thank you

Categories

Resources