unexpected token - android studio - android

I have a problem with my layout text code. Instead of displaying the code I wrote, it shows a bunch of weird symbols like :
"IHDR 0 0 �1
I thought this issue had to do with the file encoding, but I changed the global encoding to UTF-8 and still doesn´t show the code I wrote.
All suggestions are welcome. Thanks in advance.

Late answer but it will help others:
You need to delete catches folder located in:
C:\Users\user\.AndroidStudio3.5\system\caches
Make sure android studio is closed before you delete, then after deletion you can launch it and it creates a new catch folder that solves your problem,

Related

"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.

How to use user_ops in Tensorflow Android APP

I want to transplantation Faster RCNN to Android device, and I meet some problems.
I build my Android project by Bazel, just like the tensorflow demo. I add the op roi_pooling_op.cc and proposal_op.cc to user_ops, but I seems Android does build user_ops, the logcat shows as following:
tensorflow_inference_jni.cc:146 Could not create TensorFlow graph: Not found: Op type not registered 'RoiPooling'
I try to solve this problem, and I move roi_pooling_op.cc and proposal_op.cc to jni folder(maybe it is a bad ideal), the previous error is disappeared, but I meet another problem, outputs are all not found, I do not know why, logcat as following:
tensorflow_inference_jni.cc:170 Output [rois] not found, aborting!
tensorflow_inference_jni.cc:170 Output [bbox_pred/bbox_pred] not found, aborting!
tensorflow_inference_jni.cc:170 Output [cls_prob] not found, aborting!
I do not know how to solve them and I to debug, could you help me.
Thanks in advance!
Is there an output index on these nodes, perhaps? E.G. "rois:0" or "rois:1".
If you add a log line for node names/types to stat_summarizer.cc in the constructor you can see what nodes are defined in your graph which might illuminate the problem.
Adding the ops to the jni directory as you've done should work fine as a quick and dirty solution, and it seems to have done so if it got you past your initial problem.

My android app does not recognize R.string resources - what could be the reason?

I learn android with sample apps from textbook. In the given sample source R.string.something is recognized:
However, in my own EXACT source code, same R.strings are not recognized- highlighted as errors:
Does anyone know how to fix it?
I've had this many time with eclipse, and it was not a setup / code problem on my side. Generally, cleaning, rebuilding and sometime even stopping and restarting eclipse solved it. And yes, it's a pain in the neck ...
Try a clean of your project, if that does nothing then click on the problems tab and see if there's any build related issues, you may be missing a required jar or something!
These are following reason possible.
1-: You import android.R;
2-: Any error in xml files.
3-: Please check you String.xml file may be any error or declare a string more then two time.
I assume you are new to Android.
If so, there are two ways of using text strings in Buttons, textviews and so on:
1) Hardcoded string - you put the text you want in quotation marks (""), for example:
yourTextview.setText("Hardcoded string");
2) You can call the text from your String resources (res/values/strings.xml).
That is a much better approach seeing is is easier to translate, make changes and so on.
In your strings.xml file you can create all your string values, and call them from there.
Like in you example, if in your strings.xml file you have for example:
<string name="delete">This is String resource</string>
you can then call the string from there, like so :
yourTextview.setText(R.string.delete);
Hope this helps!

getResources().getString returns strange value

In my app I put a certain link in strings.xml file and then I use it in the rest of the application. Here is the way I put in strings.xml file :
<string name="link">http://mylink/</string>
and here in how I get it in my activity :
String link = getResources().getString(R.string.link);
The problem is that this String returns sometimes not the value from strings file. I get often #ff666666 and that's strange. Why sometimes it works fine and sometimes not ?
Has anyone any idea about this?
Thanks in advance.
You need to Clean and Build again before running the project.
This is happening because some times new values are added in the R.java file that doesn't get updated, so you need to clean to force the R.java file to refresh and update itself.
Try debugging into the particular method and inspect the value of R.string.link. Is it the same as you would see in the R.java file? Sometimes you get this problem when shifting around stuff in your resource files. "Project->Clean...->Clean all projects" in Eclipse usually solves it.
It is working fine. Just now i checked with following lines. Make sure sure to clean your project and build it.
<string name="link">http://www.google.com</string>
String name = getResources().getString(R.string.link);
Log.e("Name is:",name);

Android DDMS exceptions?

As i'm new to android, i really couldn't understand the errors or execptions shown in the android DDMS,I'm using Eclipse ..
Can anyone please share some very frequent exceptions that appear in DDMS and how to handle them......
We should explain exceptions here for you? Maybe you should try to read the name of the exception... most of them are named understandable. And the very first thing you should do to learn about exceptions is to read their documentation: the very famous one for example: http://developer.android.com/reference/java/lang/NullPointerException.html
If that didnt help, try to search with google or here on StackOverflow...
If you opened any xml files, this error shoud occur. Close all xml files of your application.
I'm not certain but I'm also having the same problem. I believe it occurs when you try to call something that is out of context. For example if you tried to call
TextView myTextView= (TextView)findViewById(R.id.myTextView);
when you had set a contentView as something that did not contain 'myTextView'
Hope this helps!
I think this type of error occurred when you have edited the .xml file and rebuild the project.
If you have opened any xml files, save all the .xml files and Close all xml files of your application.
and run the project. this way i run my application when this type of error occurred.

Categories

Resources