Android Studio throws "image not found" exception - java

I am facing a problem. When I was set an image in my image button then it correctly shown in design view but when I run the program then my app unfortunately stop and shows the error "resource not found" exception.
How can I fix this problem?
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_button"
android:textStyle="bold"
android:drawableLeft="#drawable/enter"
android:drawableStart="#drawable/enter" />
My image name is enter.png.

I assume you are referring this button in your code, but it doesn't have an id to refer to. You need to android:id to your xml here then refer to it in your code.

Related

No speakable text present at Android Studio

When adding a field for entering a number(Number widget), the error "No speakable text present at Android Studio" takes off
enter image description here
content_main.xml: enter image description here
activity_main.xml: enter image description here
The problem is you are missing content labeling for the view, you should add content description so the user could simply understand what data he should enter into the view
for example, if you want the user to enter the number of cookies he wants you should add a content description as seen below:
android:contentDescription="Enter How Much Cookies You Want"
You should also add an android:hint so the user would have it in front of them an example of the data you want inputted for example:
android:hint="e.g 5"
So your views XML code should look as follows
<EditText
android:id="#+id/editTextNumber2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:minHeight="48dp"
android:contentDescription="Enter How Much Cookies You Want"
android:hint="e.g 8" />
The solution is simple you just need to add the text into the hint part.
search hint in search-bar ant type something in hint block.
and hit Enter.enter image description here
The problem is missing constraints. Any view you add in Constraint layout, you must set the margins otherwise you will get those errors and even if your app managed to run, your edit text will not be place properly.
Add this to your editText;
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Let me know if it worked.
Remember you can twick this to your desired position.

Why is TextInputEditText producing this error?

I've been trying to change the fontfamily of my application to advent pro. The problem is only my textinputedittext produces this error
java.lang.RuntimeException: Font not found C:\Users\owner\AndroidStudioProjects\Application\app\src\main\res\font\advent_pro_medium.ttf
Everything works fine on buttons and textviews. I've also tried using edittext, it does not produce this error but the fontfamily doesn't get applied. I have my font in the exact same directory that the error states, so why is textinputedittext producing this error? Below is the code of my textinputedittext..
<android.support.design.widget.TextInputEditText
android:id="#+id/etJoinCode"
android:layout_width="match_parent"
android:layout_height="35dp"
android:fontFamily="#font/advent_pro"
android:hint="#string/join_code"
android:textColor="#ffff"
android:textColorHint="#ffff"
android:textSize="14sp" />
Remove android:fontFamily="#font/advent_pro" in your xml code .
1.create a new fonts directory in the assets directory and put the advent_pro_medium.ttf font file here.
2.You can change to this .
Typeface tf = Typeface.createFromAsset(v.getContext().getAssets(), "fonts/advent_pro_medium.ttf");
etJoinCode.setTypeface(tf);

android:ime Rendering Problems

I have an error with Google's Login template. I use the login activity, but I always get the following error in the rendering/design screen:
The following classes could not be found:
- EditText (Fix Build Path)
Tip: Try to build the project.
The problem is caused by the android:imeActionId xml-methods. Here is my (Google's) code:
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
If I remove all android:ime[...] lines, its rendering perfectly fine.
I use Android Studio 1.5.1 and compileSdkVersion 21
I hope you can help me to fix this issue!
Cheers!
This is due to misleading name of android:imeActionId line.
It's initial value "#+id/login" indicates it's setting its own id value, but instead it's expecting you to assign one.
Please look at Why does setting imeActionId with a predefined ID resource create an error?
It provides a solution that worked for me.

Do not show images of ImageView in real devices

I want show image in ImageView, but don't show it. I use XML code and Java code but don't show. show in simulator but in real devices don't show. tested on LG G2, HTC One X, Samsung Galaxy S3.
my xml code :
<ImageView
android:id="#+id/sms_dialog_header"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:background="#drawable/show_sms_header" />
my java code :
Dialog_Header_Img = (ImageView) findViewById(R.id.sms_dialog_header);
Dialog_Header_Img.setImageResource(R.drawable.show_sms_header);
I used to be separated from each.
Please tell me the solution
First of all you should set image in xml by code:
android:src="#drawable/show_sms_header"
not by android:background, well you can set background to color or other image but your main image you should set by android:src
If you changing something about your image, leave first line in your code that you show, and delete second, if setting image is only thing you set, then you can delete both, because you set source of image in xml.
The "src" attribute should be set to your drawable if you want it to be "centerCrop" correctly.
Check this out :
<ImageView
android:id="#+id/sms_dialog_header"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="#drawable/show_sms_header" />
Make sure that your file, called "show_sms_header", is in your drawable ( /res/drawable) directory.

EditText.setError() on single line

I have a question about EditText.setError().
I have an EditText :
<TextView android:id="#+id/sc_num"
style="#style/textLabel"
android:text="#string/scnum"
android:layout_below="#+id/creditCard"/>
<EditText android:id="#+id/credit"
android:background="#android:drawable/editbox_background"
android:layout_below="#+id/sc_num"
android:layout_alignRight="#+id/state"/>
I want to display the error message "please enter a valid security code"
using the setError() method.
When I run the app I'm getting an error displayed in multiple lines as shown in the picture
What would I do to display this error in single line?
Try android:scrollHorizontally="true".
EDIT:
Use android:SingleLine="true".

Categories