I am trying to program for Android 4.2 device but the book I have is teaches Android 4.0 called Beginning Android App Development 4. So, I am having problems running the first program targeted for Android 4.2:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is my first Android Application!" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="And this is a clickable button!" />
</LinearLayout>
error: Error: No resource found that matches the given name (at 'text'
with value
'#string/hello'). activity_main.xml /HelloWorld/res/layout line
7 Android AAPT Problem
[I18N] Hardcoded string "And this is a clickable button!", should use
#string resource activity_main.xml /HelloWorld/res/layout line
20 Android Lint Problem
[I18N] Hardcoded string "This is my first Android Application!",
should use #string
resource activity_main.xml /HelloWorld/res/layout line 15 Android Lint
Problem
I would like to where can I find the difference between 4.0 APIs from 4.2? Should I continue reading the book?
Well, that first error is simply because you haven't created a resource in your strings.xml called hello. The other two warnings are just because Android Lint wants you to use a string resource (like the first one), instead of hardcoding the strings.
Neither of these have anything to do with any differences between Android 4.0 and 4.2 however.
If you are still curious about the differences in these API levels, the Android documentation has plenty of information.
https://developer.android.com/sdk/api_diff/21/changes.html
https://developer.android.com/sdk/api_diff/22/changes.html
your problem ist not really a problem with APIĀ“S its just because you used a string that is not in strings.xml file(hardcode string). you can ignore it (should be just an advisement not a error) or just create a the string (only if you go to use that string more than once.
Related
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 :)
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.
Ok, I have been following a lesson sample at the Android Developer site and the code was thus:
<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:orientation="horizontal">
<EditText android:id="#+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
Apparently, the code should be fine, after worrying I typed it in wrong, I ended up copying it directly but the Console is telling me:
Description
error: Error: No resource found that matches the given name (at 'hint' with value '#string/edit_message').
Description
error: Error: No resource found that matches the given name (at 'text' with value '#string/button_send').
Now these values are defined in the strings.xml file. So I have no idea why I would be getting these errors.
To anyone who can help here is a big thank you in advance.
Try in eclipse project>clean . Sometimes eclipse give you errors like these. Or restart eclipse. Did you also make sure at your strings.xml you have something like this ?<string name="edit_message">Your intresting string.</string> sometimes if you use the 'gui resource adder' It gives mistakes. Check inside your xml.
make sure there is no capital characters or underscores in any file inside res.
Also , there must no any error inside the files of res and src ..
after that you have to clean the project as mentioned in previous answer.
Actually these errors prevent the R file to be updated which is necessary to access resources inside res file.
I'm trying to create a custom ListView layout similar to android.R.layout.simple_list_item_2. However, when I use the following in my XML I get an error saying "No resource found matching the given name ?android:attr/listItemFirstLineStyle".
<TextView
android:id="#+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/listItemFirstLineStyle" />
Can someone tell me how to rectify this or how to find the style properties so that I could copy them. I'm using Android 2.2.
Found the problem - android:attr/listItemFirstLineStyle was for an old version of the SDK I guess. For 2.0 and above - use android:attr/textAppearanceLarge NOT android:attr/listItemFirstLineStyle
http://www.google.com/codesearch/p?hl=en#uX1GffpyOZk/core/res/res/layout/simple_list_item_2.xml
I'm working on a couple of apps at the moment while I try to learn my way around the Android SDK. I had a bit of trouble recently with my layouts where I was defining, for example, an EditText element as such...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="#+id/price_per_pack"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/price_per_pack"
android:layout_alignParentLeft="true"
android:textSize="12pt"
android:text="Price Per Pack"/>
</LinearLayout>
The application was compiling correctly, however when I attempted to start the activity which utilizes this layout nothing would happen. Through a process of elimination I identified the id attribute as the troublesome one and while playing about I discovered that changing
android:id="#+id/price_per_pack"
to
android:id="#+android:id/price_per_pack"
solved my problem and the application behaved as expected. My initial attempt at declaring the id attribute was based upon examples in the SDK documentation so I'm wondering if somebody could explain to me why I needed to make the above change to get it working?
I'm sure that it won't make any difference but I'm developing using the android-mode.el emacs plugin and have a completely up-to-date copy of the SDK.
Thanks in advance.
From Android Documentation:
With the android package namespace in place, we're now referencing an ID from the android.R resources class, rather than the local resources class.
It looks like you might have some syntax errors in your code posted.