Android - Strange bug or something wrong with my file structure? - android

After today's work on my Android app, this started happening:
1: Android Studio say that the ID: welldana_image isn't there, even though it's right above: (Image below)
^ This problem persists all the way through this .xml file (activity_calculate_mine.xml)
2: The two project "show package" types aren't matching. In the first picture (Android style), the layout file activity_calculate_mine.xml isn't there, but in the second (Package style) picture, it is. (Pictures below)
EDIT: Everything works fine. I just don't want to push this to the marketplace, and suddenly it won't work. But everything works fine at the moment, though seeing these errors.
EDIT 2: Now this has happened? Is there an error in my manifest that I can't spot?
EDIT 3: Luckily I saved myself a copy of the project before everything went nuts. Apparently I deleted the activity_calculate_mine.xml. I solved this problem by simply placing the old version in the same directory as of before, and then just copy pasting the activity_calculate_mine.xml back into it's original placement.
Problem solved. Thank you.

Remove the "+" sign in the line android:layout_below="#+id..."
The #+id defines an id value, the #id referes to one.
Change this:
android:layout_below="#+id/welldana_image"
To this:
android:layout_below="#id/welldana_image"

Related

Android layout ids not recognised

I'm trying to get Android studio to recognise IDs of various views etc. in my layout.xml file. When I was inputting the code in the xml, everything seemed OK, but when I revisited my code today, the ids in the layout file were in red saying "cannot resolve symbol."
When I tried to access the view (eg using "view.findViewById(R.id.splo)"), it says it cannot resolve the symbol (in this case "splo").
I'm not doing anything radical, for instance this is how I define splo in my layout xml:
<TextView android:id="#+id/splo" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="" />
Doing some digging, I found that I don't have a res/values/id.xml file - and looking further I don't have anything below app/build/generated/source, so no R.java file either.
I've looked at some people's requests for help - one was very similar to mine ("cannot resolve symbol R" in Android Studio) but the solutions offered don't help.
I've done multiple invalidate cache and restart, with or without Build->clean project and nothing works, and the IDs are still not recognised. Can anyone help?
Well there might be potential errors in the package name when you are building your application.
Since you mentioned, you already tried rebuilding and cleaning the project, we won't waste time doing that again!
What I want you to do now is:
Open your AndroidMainfest.xml file
Scroll to the top and check is the package name is correct
If its correct then go to the Activity definitions in the manifest and check:
If the package name in these lines [android:name="YOUR_PACKAGE_NAME.YOUR_ACTIVITY_NAME"] is correctly assigned
If you see the above line is in this format [android:name=".YOUR_ACTIVITY_NAME]", then bring it in the above format by adding the package name before the dot.
Now clean and rebuild your project.
The problem should be solved and if not my request is that please
Upload your AndroidManifest.xml file and your package
information so that I can have a better look at the issue

"invalid symbol name" after Android Studio crashed

I was editing a layout in Android Studio and added a Switch.
I first set its ID to "switch". After a compilation error, I realized it was a reserved keyword and I cannot use it, so I decided to change its ID to "mySwitch" but Android Studio crashed at this moment.
After launching it again, I checked the ID, which does have been changed to "mySwitch", but when trying to compile, I still get this error:
/path/to/app/build/generated/source/r/debug/com/example/program/R.java: error: invalid symbol name 'com.example.program:id/switch'.
I guess Android Studio did not change all occurences of "switch" before crashing, but I did not find any.
What I tried but did not work :
Changing again the ID
Deleting and adding again the Switch
Clean Project
Is there any occurence of my Switch ID I did not think of ?
I found the problem, I should have thought of that earlier.
What I did is right click on "my_layout.xml" > Analyze > Inspect Code...
Then it showed me this line
app:layout_constraintEnd_toStartOf="#+id/switch"
I don't know how I missed that...
you need to find where in your xml code an object had taken "null" as an id android:id="#+id/null"
so first you need to go to the last xml you edited
1 - click right on it
2 - Analyse
3 - Inspect Code ...
4 - click ok and you will see how much errors and warnings you have
try manually deleting the build folder in your project and use "build" -> "Rebuild Project". By that way all mapping files (including your inconsistent layout mapping) should also go away. and Rebuilding recreates the map.
I still doubt, if you have missed to change id with name switch somewhere else. Think that way also..
same xlm file you declear samething like
`android:id="#+id/null`enter code here`
find it and fix;
from right click on eath xml file..and run analyze--->Inspect Code
You have to check your last edited xml file if it shows the error of invalid name symbol where id is assigned to null go through the code and check all the id's in my case the layout constraints were assigned null value. Check the id's and either remove them or assign them suitable values
Ensure that you have not named your resource a system reserved name like Continue.xml or such.

"is translated here but not found in default locale" error in strings.xml with translatable="false"

Here is my values\strings.xml (the default file) and everything is self explanatory:
My question(s):
How can it be "not found in default locale" if I am editing the default locale (values\strings.xml)?
How can it be a lint translation error if I set translatable="false"? In the values-pl\strings.xml (and values-ru, values-iw folders as well) the strings don't exist even? it shouldn't anyway.
I can't seem to understand why I don't get the error for the Russian string.
(I would show the values-ru\string.xml or values-pl\string.xml here but there is nothing there of interest, since the strings are missing anyway...)
this happened to me too
I do 2 things:
Verify entire file to see another translate not done ( I have ones in file en but in pt-br)
Clean, update gradle and quit and restart the Android Studio
Rebuilding can take a long time. YMMV, but...
Simply remove the offending line and re-add it.
Worked for me. Very fast.
In my case this helped me:
Select the strings that cause error.
Cut them.
Paste them again
If it doesn't work for you, try adding the same strings to strings.xml(v21) file.
Press Invalidate Caches / Restart ... to restart android studio. It worked for me. Actually this happened when I had copied files from my other computer and pasted via file explorer.
I solved this issue by following below steps:
cleaning my project
rebuilding it
and finally pressing invalid caches/ Restart in file menu
If you just Clean Project it probably works. It worked for me.
I had the same error message, just with the weird issue that it was thrown in the default locale itself and all translations. Turns out you should not use dots in your name (e.g. name="bla.blub") because it will be internally converted to "bla_blub" and then it cannot match with "bla.blub", hence the error.
I only had to change the dots to underlines in the default locale and then all other errors in other translations (including dots in the name) were gone as well.
But be aware that other build tools can still create issues, so replace all the dots with underlines instead!
Quitting Android Studio and restarting it fixed it for me.
You simply just have to copy the offending line (or just one of the multiple of offending lines), remove it, and re-paste it. That removed the issue for me.
Just make sure that you have same naming conventions on all strings files including the same capitalization.
let's say if you have "sign_in" in strings.xml and "sign_In" in your fr/string.xml, so it will give you error on fr/strings.xml like "is translated here but not found in default locale". So, when you edit to "sign_in". The error will remove.
I was having this problem for all the strings in my xml file.
The thing is, your default strings.xml shouldn't have a tools:locale attribute as the other translated files have. If it does, whenever I compile the app in release mode, it treats it as another translated file.
I've created a tool to manage the translation status of android apps.
It not only tells you what strings are missing on the other languages, but it can also report, and clean the left over strings that you may have deleted on your default translation file.
https://github.com/gubatron/android-missing-strings
To clean all left overs in other languages invoke like this
./ams --cleanleftovers -o all.txt
This will clean the left over strings and it will output the missing strings report for all the languages into the all.txt file
Copy and paste didn't work for me.
I also tried Clean and restart, the previous error was gone but new entered strings still have new errors occur.
I tried closing the opened strings.xml file and Translations Editor, then restart.
strings.xml file and Translations Editor
That works for me.
Well, in my case, this happened when there was a format error with the previous string of the string that's being reported. Unfortuantely that format error was not reported. Correcting the format error solves the issue.
Add this,It will work
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ExtraTranslation">
Press double shift for open Translations Error and then check and uncheck in Untranslatable column the item with error.

String is not translated android

When I tried to open my android project in eclipse a few minutes ago I got these errors telling me the the strings in the strings.xml file are not translated to other languages (this morning everything was good).
I found something online that said I should change MissingTraslation to Warning instead of Error, but it didn't help.
What should I do?
it's shown by the Lint tool.
just change its settings (to warning/info/... instead of error), and run Lint again (the button on the toolbar, near the button of launching the app, looks like a checkbox with a "V" in it, looks similar to this one ).
Try this:
http://tools.android.com/recent/non-translatablestrings
juste put translatable="false.
Best regards,
Yassine

Content won't resolve

I'm working through a book samples programs and i get the same problem whether I create and type the code or whether i download the code already typed, so i'm thinking it's a setup problem.
I get this error in each each class:
setContentView(R.layout.menu) where the "R" is underlined in red and the code won't compile. If i add import android.r like "QuickFix" suggests, the red line goes away from the "R", but then the red line appears under "menu" (in this example). The same behavior occurs in each of the 5 classes that make up the project.
I do have matching layouts for "menu" etc. And (to the best of my knowledge) I registered them as Application Nodes in the manifest file.
It's driving me nuts. Thanks for any suggestions.
You are not supposed to import android.R as it won't resolve your resources. Just remove that import and try to compile again.
If you are working off a tutorial then also check to have the same resources as in the tutorial and also if you decide to name thing different then keep that in mind an reference them by your names.
The R class is generated by Android and contains IDs for all resources in your res folder. Go to your AndroidManifest and locate the package= attribute on manifest. R is in this namespace. So if the namespace is com.yourpackage.blah, you'll want to import com.yourpackage.blah.R;
The problem was that for some reason Eclipse was not autogenerating the gen/R.java file. I don't know why. One time it did generate the file, and a after Project..Clean and Build All everything resolved. Thanks for the input.
Also make sure your file names under res, eg drawables, are OK. I had a file name with capital letter and that prevented the creation of R with the same reference errors that you got. I did not check the error messages and it took me a good 10-20 mns to find this out.
Sometimes this happens to me.
It usually happens that I have been working with some xml element, and before clicking to a java document to hit "run" i just hit "run" while on the xml. I don't really know what happens when you "run" an xml, but it makes this horible file called some_xml_name.out.xml.
DELETE THIS FILE!
This file is the reason why you get so many R related errors, since the Resources library is never really created, or something like that.
That is my advice, without actually seeing the error you're getting in the console.

Categories

Resources