I made projects in Eclipse with ADK, but today i have installed Android Studio, created my first project HelloWorld and faced with problem: I added one ImageView, if I set beckgroung (or src) with any system resources - all right, but when I set my box.png file I get errors:
1. execution failed for task ':app:mergeDebugResources'
2. no resource found that matches the given name (at 'background' with value '#drawable)
I tried all the options of the website https://stackoverflow.com/ and others with same problems, but I didn't solve my problem yet.
Please, help me !
<?xml version="1.0" encoding="utf-8"?>
<TextView android:text="Hello World!" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:id="#+id/imageView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="#drawable/box" />
Related
I'm trying to use MaskedEditText for the phone number.
This is the xml code:
<br.com.sapereaude.maskedEditText.MaskedEditText
android:id="#+id/phone"
android:inputType="number"
android:layout_width="200dp"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:hint="Phone number"
app:met_mask="+## (###) ### ## ##"
android:maxLength="13"
android:textAlignment="center"
android:textSize="20dp"
/>''
What I added to grade:
implementation 'ru.egslava:MaskedEditText:1.0.5'
And the errors are:
error: attribute met_mask (aka com.example.app2:met_mask) not found.
error: failed linking file resources.
Please help me!
According to the library which you are using https://github.com/egslava/edittext-mask,
<br.com.sapereaude.maskedEditText.MaskedEditText
android:id="#+id/phone_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:typeface="monospace"
mask:allowed_chars="1234567890"
mask:mask="+7(###)###-##-##"
android:hint="1234567890"
app:keep_hint="true"
/>
You are using the property:
app:met_mask="+## (###) ### ## ##"
but library allows:
mask:mask="+7(###)###-##-##"
So, please use it accordingly as it is specified.
Hope it will work!!!
I used constraint layout Android Studio 2.3.1 with constraint-layout:1.0.0-alpha4 dependency before, but now I am using 'com.android.support.constraint:constraint-layout:1.0.2', layout_constraintGuide_Percent attribute is not exists.
Which attribute replace for layout_constraintGuide_Percent?
my code:
<android.support.constraint.Guideline
android:id="#+id/guideline_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_Percent="0.8"
tools:layout_editor_absoluteX="50dp"
tools:layout_editor_absoluteY="0dp" />
Replace the attribute with this
app:layout_constraintGuide_percent
I want to link to an out-of-app resource on Android with pure HTML in XML without having to call setMovementMethod. Setting:
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/the_message"
android:autoLink="web"
android:linksClickable="true" />
Does not work. Help?
i was doing small android application , i added blank xml file but it was showing some error although i did not add any code and still it was showing error so i cleaned project but now after cleaning for my activity when i write
setContentView(R.layout.reminder_edit);
its giving errors like this R cannot be resolved to a variable ,
for another activity named ReminderListaActivity i tried this
setContentView(R.layout.reminder_edit)
error was for xml file not for "R " error was :reminder_edit cannot be resolved or is not a field .
xml file is in layout and its showing like never used file so how do i solve this issue , can someone help me with it pleae
EDIT code added
reminder_edit.xml
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:text="#string/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/body"
/>
<EditText
android:id="#+id/body"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minLines="5"
android:scrollbars="vertical"
android:gravity="top" />
<TextView
android:text="#string/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/reminder_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Reminder_Time"
/>
<TextView
android:text="#string/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/remindertime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/remindertime"
/>
<Button
android:id="#+id/confirm"
android:text="#string/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</ScrollView>
java File
public class ReminderEditActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder_edit);
}
}
Fix the errors in XML so the resource compiler can generate R.java for you.
Remove Import android.R; from imports in your activity class
In order to accesst "R.layout.edit_reminder" xml file you must import your "R" file which is found under the "gen" folder. This file is automatically generated, so you can go ahead and delete it and it will be generated again. Now, if you have any xml errores whatsoever the R file won't be generated, that's a sign that you have to look to your xml to find the problem.
In regards to the import, you'll find them on your Activity Class, at the very top right after the package declaration.
Make sure that the R you are importing is:
yourpackage.R;
rather tahn
android.R;
When writing code quickly at times android.R gets imported and you don't even notice. That's the first thing I always check, it's happened to me a couple of times already.
Next thing I would suggest doing is looking to see your console and problems view (if these are not set in your perspective, then go to Window>Show View>Other and select the appropriate ones).
Look for something along the lines of Error with xml file aborting build. Look for what xml file it is talking about, and then look for errors in it.
I'm doing the exercise "sudoku" from the book "hello to android".
I saw some people have the same issue as me but I'm unable to solve it.
I have deleted three times this project and re-create from the beginning but I keep getting the same error message on below, even if I'm doing a copy/paste from the book.
W/ResourceType( 8592): Bad XML block: header size 29806 or total size 538970658 is larger than data size 0
C:\java\Sudoku\res\layout\activity_main.xml:6: error: Error: No resource found that matches the given name (at 'text' with value '#string/hello_world').
C:\java\Sudoku\res\menu\activity_main.xml:2: error: Error: No resource found that matches the given name (at 'title' with value '#string/menu_settings').
There is the code inside the book for the Sudokuv1/res/layout/main1.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/main_title" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/continue_label" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/new_game_label" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/about_label" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/exit_label" />
</LinearLayout>
There is the code for Sudokuv1/res/values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Sudoku</string>
<string name="main_title">Android Sudoku</string>
<string name="continue_label">Continue</string>
<string name="new_game_label">New Game</string>
<string name="about_label">About</string>
<string name="exit_label">Exit</string>
</resources>
Thank you for your help!
If you created the android app with the Elcipse plugin, in the res folder you have a menu folder and inside that folder there is another activity_mail.xml.
Erase the file or comment its content since you wont be using the menu for the sudoku app.
That should fix it.
either add
<string name="hello_world">hi</string>
to your string.xml
or find the view called 'title' in your activity_main.xml and erase the android:text="#string/hello_world" property from it.
Delete the file activity_main.xml from res>menu because there are two files with the same name in res>menu and res>layout.