Text in XML Graphical Layout appears as strange characters - android

I am having issues viewing text in the graphical layout section of my android applications. This is consistently happening across many projects, new and old. See the link for visual example: http://i.imgur.com/OwENudf.jpg
The button in the image should say 'test' but instead its two boxes. Sometimes it appears as an open bracket, [
Background- I was having issues with eclipse/android sdk not creating the R.java file when a new project was created so I uninstalled the sdk and then reinstalled it. The R.java file builds fine now but the text in the graphic layouts is all strange characters.
Any idea what I can do to fix this?
The XML has one warning, which is 'Hardcoded string "test", should use #string resource"
I don't think this is the issue because I have had this error before on working applications.
EDIT:
XML code-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:text="test" />
</RelativeLayout>

I believe you are having font issues with your emulator. It can't find appropriate characters to display. You may need to reinstall that.

Ok so I searched and I think it will fix your problem (and it was too long to post it as a comment).
Go to the platforms folder where android-sdk is installed (C:\Program Files (x86)\Android\android-sdk\platforms).
Then go to the folders you're currenlty building your projects with then go to data/fonts (i.e C:\Program Files (x86)\Android\android-sdk\platforms\android-8\data\fonts) and take a look at the file fonts.xml. Also, may a ttf file disappeared when you updated your ADT (which seems odd).
You can find here an example. Read this carefully before trying to modify these files.
I hope this will solve your problem. If not, I have really no idea about what to do.

Related

Changing name of main actvity, hard-coding text

I'm a noob who has a book on Android programming that is using an older version of Android Studio. I have Android Studio 3.3. I want to learn on the latest Android Studio, but the steps to naming an activity are completely bypassed in AS v3.3. The book names the activity beer activity, so I thought I would just rename main activity to beer activity. Error things going red, arghh...
I think I figured out how to rename things in the coding and I got rid of a lot of red, but it crashed when compiling. Then I renamed the main activity in my manifest. Now it runs with title, but won't display text says hard-coding no good. I still get a little lightbulb that complains about resources, and I think I still need to change something somewhere.
Here is the XML code that was named main something, I think. I forgot. Is this code not usable anymore in 3.3? I ran into deprecated things several times. I thought I was buying an up-to-date book copyright November 2018, but Android Studio 3.3 just came out recently, the stable version I think.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:orientation="vertical"
tools:context="com.hfad.beeradvisor.FindBeerActivity"> (changed name here)
<TextureView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is text view" (wont display)
/>
</LinearLayout>

No resource identifier found for attribute 'srcCompat' in package '....'

I will being by saying that I have seen SOME answers for this question on stackoverflow already, but only providing a quick 'fix' solution. I would like, if possible, to also understand WHY this is happening (an answer with some detailing).
Now to get to the question: I have just re-started android development, using Android Studio 2.2 . I have an ios app which I want to port to android (meaning, recreate it for Android). I have started with a basic template from Android Studio, added a Constraint Layout and 2 ImageViews using 2 PNG files that I have copied in DRAWABLE folder.
Without making any changes or whatsoever , when I try to build I get this error:
Error:(11) No resource identifier found for attribute 'srcCompat' in package 'x.y.z'. This happens for both images. Here is the layout file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/lib/x.y.z"
xmlns:app2="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="x.y.z.MainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app2:srcCompat="#drawable/pngFile1"
android:id="#+id/imageView"
app2:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="8dp"
app2:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app2:srcCompat="#drawable/pngFile2"
android:id="#+id/imageView2"
app2:layout_constraintBottom_toTopOf="#+id/imageView"
app2:layout_constraintRight_toRightOf="#+id/imageView"
android:layout_marginBottom="8dp" />
Now, here are some things that I would like to understand, in order to have a proper answer to my question:
some of the other answers I have found on SO propose to change the default:
xmlns:app="http://schemas.android.com/apk/res-auto"
to:
xmlns:app="http://schemas.android.com/apk/lib/x.y.z"
It's true that this removes the error from the build, but what seems strange to me (with my little-to-none android experience), is that Android Studio creates then another similar line when i add the 2nd image:
xmlns:app2="http://schemas.android.com/apk/res-auto"
And as we can see, it uses this for the images, so the errors appear again.
I remember like one year ago i had worked on an app on Android Studio, and have used almost the same way of adding images / buttons with images and these problems were not there.
That's why I would also like to understand why this is happening and how to fix it properly.
Thanks in advance !
Fist of all you need to concentrate on the version of android studio you are using. You should also look at the minSdkVersion and targetSdkVersion.
Try to use android:src="" instead of app2:srcCompat=
app2:srcCompat= suports older APIs when loading vectorDrawable.
If you want to use it,then amend your build.gradile like,
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
For more information you can refer to this link
or you can refer to this answer at stackoverflow
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:background="#drawable/cooltext201199220690445" />
I just changed mine into like this and it worked for me
I just removed that srccompat and replace it with "background"
and i completely removed "xmlns:app2="http://schemas.android.com/apk/res-auto" hope this helps you :)

R doesn't generate button

I've just finished to do the layout I want, and even although I saved everything, when I try to find by id the button, the button I'm looking for is missing.. Both the button's I have.. I've checked in the R class, under the ID, and it seems it doesn't sees' the buttons. Doesn't generate them? I dunno.. Any way, it happens every time I use relative layout!! Is there any connection? It works with TableLayout and with linear layout.. Only with relative layout it make's problems.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/Background" >
<TextView
android:id="#+id/corpTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/corpTag"
android:textColor="#color/White" />
<Button
android:id="#+id/addBusinessButton"
style="#android:style/ButtonBar"
android:layout_width="200dp"
android:layout_height="25dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="208dp"
android:text="#string/addYourBusiness" />
<Button
android:id="#+id/searchBusinessButton"
style="#android:style/ButtonBar"
android:layout_width="200dp"
android:layout_height="25dp"
android:layout_alignBottom="#+id/addBusinessButton"
android:layout_alignLeft="#+id/addBusinessButton"
android:layout_marginBottom="36dp"
android:text="#string/searchBusiness" />
I found this happening to me with a broken layout. No need to be worry. I am trying my best to giving you the solution
Solution
Make sure that anything the R. links to is not broken. Fix all errors in your XML files. If anything in the ADKs are broken, R will not regenerate.
If you somehow hit something and created import android.R in your activity, remove it.
Run Project -> Clean. This will delete and regenerate R and BuildConfig.
Make sure Project -> Build Automatically is ticked. If not, build it manually via Menu -> Project -> Build Project .
Wait a few seconds for the errors to disappear.
This problem isn't related to relative layout, but is actually set on the background because Android drwable is case-sensitive and now allows you any capital letters for image or layout. Rename your image name or drwable name to "background" instead of Background."
Here is the problem with set background name:
android:background="#drawable/Background"
It might be the Android Style ButtonBar. It isn't available for every API level. So if you have a low minSDK, it's not going to build and Eclipse/IntelliJ should give you an error message in its error pane.
The rule given by Google, is that you should always define your own resources. If you want to use a resource that is in the Android name space, that's fine, but you should copy it first and package it with your apk, because that's the only way you can be assured that it will always be bundled with your application.
And yes, I realize many people and many tutorials on the web don't do it that way, but that's because most people are lazy.

could not resolve resource android eclipse

I am new in andorid development.
I have created my android first project according to http://developer.android.com/training/basics/firstapp/creating-project.html
And here is the code that I have as the project was created(no changes are done in code by me)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
Here is the screenshot of the Graphical layout
http://imageshack.us/a/img35/5284/android1s.png
So, it looks fine for now, but if I want to change the text Hello world to , say, hello, so the code's part looks like android:text="#string/hello", I get the error
NOTE: This project contains resource errors, so aapt did not succeed, which can cause rendering failures. Fix resource problems first.
and
Couldn't resolve resource #string/hello, and the text in graphical layout becomes
#string/hello, as it is in this image
http://imageshack.us/a/img826/7735/android2p.png
But I noticed one thing:
If after this error I go to res/values/strings.xml and add String with name and value hello, like
http://img842.imageshack.us/img842/8108/android3s.png
The error disappears and I can see the word hello in the graphical layout.
I tried these so far
Using ctrl+shift+s like it is described here https://stackoverflow.com/a/14462434/932473
Closing and reopening Eclipse.
cleaning, rebulding
removing the entire project and creating again.
The values folder does exist in res.
None of these questions solved my problem
Eclipse could not resolve string resource error
Can't Resolve Android Resource Strings
UPDATED
If I write like this android:text="hello"
I get this warning in eclipse
Hardcoded string "hello", should use #string resource,
I do not get it every time I want to use some string like android:text="#string/hello2", I have to first manually specify hello2 it in strings.xml ?
In res/values/strings.xml
<string name="hello">Hello</string>
Then refer the string in your textview as
android:text="#string/hello"
I guess you do not have something similar to above. Hence you get resource not found exception coz the resource is not defined in strings.xml
or
You can do as below
<string name="hello_world">hello</string> // change the string in strings.xml
android:text="#string/hello_world"
For the question in the comment
You can just use
android:text="hello"
the #string bit means its a resource called hello in your xml.
So you can also add the resource to your xml if you wish. Its known to be better practice, for internationalization.

Android XML Viewer failing

I've been having this problem for a while:
Here is my header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/logo_text"/>
</LinearLayout>
And this what the Eclipse/Android XML viewer is giving me:
Unable to resolve drawable "C:\Users\Me\MyApp\res\drawable-hdpi\logo_text.png" in attribute "src"
This happens in other projects as well for seemingly random images. Project->Clean doesn't help either. I know this has to be an issue with my machine or eclipse installation because it doesn't happen on my work machine, only my home laptop.
There are no problems when the app is installed, but it would be nice to be able to see layout changes without having to install the app over and over again.
EDIT
I also get these messages anytime I use a custom View in a layout file:
error!
UnsupportedClassVersionError: Bad version number in .class file
Unable to resolve drawable "C:\Users\Me\MyApp\res\drawable-hdpi\logo_text.png" in attribute "src"
Exception details are logged in Window > Show View > Error Log
I sometimes have weird issues like this when importing new images into my project. Do you have any other res-image directories with different versions of this file? You may try removing the png and re-adding to the project.
The error message explicitly mentions the -hdpi version of the drawable directory. Have you got that image in all of the different versions of the drawable directory? Perhaps it is in res/drawable-ldpi or res/drawable-mdpi but not res/drawable-hdpi?
If you don't already have one, you could create a plain res/drawable folder and add the image there, then one would expect the system to fall back to that whenever it didn't find a definition-specific version.
Actually try to put an id tag on ImageView : android:id=:"#+id/imageView".Tell me if it is working or not.

Categories

Resources