whenever i hit the imageview i get this error, this happens to me when i switch to test my app on different screen sizes, here is my xml
<ImageView
android:id="#+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="28dp"
android:layout_marginRight="28dp"
android:layout_marginTop="20dp"
app:srcCompat="#drawable/search"/>
and here is the error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ahmed.electionadmin, PID: 30789
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ahmed.electionadmin/com.example.ahmed.electionadmin.Search}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
I have tried so many solutions that asks me to replace src with srccompat and so on, but still is working, ant help would be appreciated
To use srcCompat you need to add vectorDrawables.useSupportLibrary = true to your build.gradle file:
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
Or you can use src instead of srcCompat to resolve the error.
android:src="#drawable/search"
Replace this:
app:srcCompat="#drawable/search"
With:
android:src="#drawable/search"
Pay attention, not only src with srcCompat, also app with android.
Let me know if it works.
Explanation: You're not using a support library ImageView, but a regular one. app namespace is usually used for support library, same as srcCompat. So you needed to change those 2 things, not just one. That's why merely changing the srcCompat with src yielded no results.
i fixed it by uploading my image inside draawable no 24
you are doing like fitting image to different resolutions , you should have image with different resolutions like hdpi xhdpi , you you can use vector drawable image
Related
On some Android devices, I am getting "Resources$NotFoundException: Drawable (missing name) with resource ID" error, e.g.:
On LGE Android 8.1 devices it is complaining
Unable to start activity ComponentInfo{SplashActivity}: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class ImageView
For the following part. In particular, it is complaining "android:src="#drawable/red_logo""
<ImageView
android:id="#+id/logoImageView"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:src="#drawable/red_logo" />
I checked the source code directory, "red_logo.png" already exists in the following folders:
drawable
drawable-hdpi
drawable-ldpi
drawable-mdpi
drawable-xhdpi
drawable-xxhdpi
drawable-xxxhdpi
Here is the Java code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash); <---- Fails here
}
The dimension of red_logo.png in drawable folder is 4864 × 2692, same size as the red_logo.png in drawable-xxxhdpi folder. Is it too big?
I did a lot of research but it seems I cannot find a valid answer.
Thank you.
Best regards.
It happens due to scale issues, hence, always use a vector asset instead of an image in such scenarios. Worked for me.
On some devices there is no problem but on some such exception appears when opening src of ImageView.
The stack trace looks like this:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{pl.jawegiel.endlessblow/pl.jawegiel.endlessblow.activities.MainActivity}:
android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class
ImageView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666) at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) at android.app.ActivityThread.-
wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) at
android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at
android.app.ActivityThread.main(ActivityThread.java:6121) at java.lang.reflect.Method.invoke(Native
Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) Caused by: android.view.InflateException:
Binary XML file line #11: Binary XML file line #11: Error inflating class ImageView Caused by:
android.view.InflateException: Binary XML file line #11: Error inflating class ImageView Caused by:
android.content.res.Resources$NotFoundException: Drawable (missing name) with resource ID #0x7f0800cd
Caused by: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f0800cd at
android.content.res.ResourcesImpl.getResourceName(ResourcesImpl.java:228) at
android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:687) at
android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571) at
android.content.res.Resources.loadDrawable(Resources.java:858) at
android.content.res.TypedArray.getDrawable(TypedArray.java:928) at android.widget.ImageView.
(ImageView.java:162) at android.widget.ImageView.(ImageView.java:150) at
androidx.appcompat.widget.AppCompatImageView.(AppCompatImageView.java:74) at
androidx.appcompat.widget.AppCompatImageView.(AppCompatImageView.java:69) at
androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:199) at
androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:119) at
androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1551) at
androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1602) at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769) at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) at
android.view.LayoutInflater.rInflate(LayoutInflater.java:858) at
android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at
android.view.LayoutInflater.inflate(LayoutInflater.java:518) at
android.view.LayoutInflater.inflate(LayoutInflater.java:426) at
android.view.LayoutInflater.inflate(LayoutInflater.java:377) at
androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696) at
androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170) at
pl.jawegiel.endlessblow.activities.MainActivity.onCreate(MainActivity.java:50) at
android.app.Activity.performCreate(Activity.java:6682) at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619) at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) at android.app.ActivityThread.-
wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) at
android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at
android.app.ActivityThread.main(ActivityThread.java:6121) at java.lang.reflect.Method.invoke(Native
Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
MainActivity.java:50 looks like this:
setContentView(R.layout.activity_main);
ImageView that causes problem looks like this:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/splash2"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:contentDescription="TODO" />
this splash2.png is located in res\drawable, res\drawable-hdpi, res\drawable-mdpi, res\drawable-xhdpi, res\drawable-xxhdpi and res\drawable-xxxhdpi so I guess in correct folders. So how to solve that?
Thank you in advance!
You may be able to solve this problem with a more generalistic approach:
Try using scalable vector graphics (SVG) instead of .PNG-images. VectorDrawable is more flexible if you need to match different screen resolutions.
PNGs can be transformed into scalable vector graphics with Inkscape or online PNG converter (https://convertio.co/de/png-svg/)
After that you can create a new VectorDrawable by loading the SVG. VectorDrawables can be assigned with app:srcCompat="#drawable/ic_VectorDrawableName"
Documentation:
A VectorDrawable is a vector graphic defined in an XML file as a set
of points, lines, and curves along with its associated color
information. The major advantage of using a vector drawable is image
scalability. It can be scaled without loss of display quality, which
means the same file is resized for different screen densities without
loss of image quality. This results in smaller APK files and less
developer maintenance. You can also use vector images for animation by
using multiple XML files instead of multiple images for each display
resolution.
VectorDrawable also requires much less RAM than .PNG.
You may find the cause of your errors in this thread:
Resources$NotFoundException drawable-xhdpi from drawable resource
The SVG that I was attempting to import was not correctly formatted, this lead to the xml for the vecto image not being correctly formatted either Try the following samples here as these are all correctly formatted SVGs.
I am attempting to add a SVG image into a ImageView but i keep on getting an error every time I try to call its #drawable/ value. The file seems to be in the right location since when I use a PNg image it works, but it does not get recognised when its an SVG image.
The XML to add the image is :
<ImageView
android:id="#+id/statusImage"
android:layout_width="304dp"
android:layout_height="391dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/statusText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_temp" />
and the location of the image file is:
I have tried to modify the Gradle file so that it contains:
vectorDrawables.useSupportLibrary = true
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
But that does not seem to solve the issue I'm having.
The error log seems to print that :
E/AndroidRuntime: FATAL EXCEPTION: main
Process: sc17dpc.individualproject, PID: 3467
android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class ImageView
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class ImageView
Caused by: android.content.res.Resources$NotFoundException: Drawable sc17dpc.individualproject:drawable/ic_temp with resource ID #0x7f07006d
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_temp.xml from drawable resource ID #0x7f07006d
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:1166)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:917)
at android.content.res.Resources.getDrawableForDensity(Resources.java:1074)
at android.content.res.Resources.getDrawable(Resources.java:1013)
at android.content.Context.getDrawable(Context.java:630)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:463)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:203)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:102)
at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:59)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:78)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
at android.support.v7.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:182)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:783)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:874)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at sc17dpc.individualproject.HomeFragment.onCreateView(HomeFragment.java:23)
and points to my class HomeFragment on the line:
View view = inflater.inflate(R.layout.fragment_home, container, false);
Any help is appreciated since the solutions that I've followed currently have not solved the problem.
*********EDIT*********
The SVG file is imported using the "New -> Vector Asset" built in feature in Android Studio and by using a local file.
The image file looks like:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="640dp"
android:height="640dp"
android:viewportWidth="640"
android:viewportHeight="640">
<path
followed by a load of information about the image path.
I have attempted to change app:srcCompat to android:src and this still gives the same error as before.
Can you try again?
android:src="#drawable/ic_temp"
You can't use viewportHeight and viewportWidth as 640
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="640dp"
android:height="640dp">
Source VectorDrawable
Issue has been sumarised at the top of the article. Thanks for the help.
I am developing a homescreen widget that has a number of different sized buttons. To maximize the use of space, I want to use a flow layout for this widget (which for some crazy reason, android has no native implementation of).
To solve this, I have tried using third party implementations and implemented the layout myself, however, I always get an exception when loading the widget:
W/AppWidgetHostView: updateAppWidget couldn't find any view, using error view
android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class [redacted].FlowLayout
Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class [redacted].FlowLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "[redacted].FlowLayout" on path: DexPathList[[zip file "/system/priv-app/Velvet/Velvet.apk"],nativeLibraryDirectories=[/system/priv-app/Velvet/lib/arm64, /system/priv-app/Velvet/Velvet.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64, /system/lib64, /vendor/lib64]]
My layout for the widget looks only like this:
<[redacted].FlowLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#09C"
android:padding="#dimen/widget_margin"
android:id="#+id/widgetRoot"
android:orientation="horizontal">
</[redacted].FlowLayout>
Assuming that the redacted namespace is correct, is there any way to do what I want or is it impossible to use a custom layout with a homescreen widget?
Home screen widgets are wery limitted things, they doesn't support custom layouts: https://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout
I've read everywhere - couldn't find a solution.
My project was working fine, I stated the methods I wanted to be called to the onClick inside the XML file like this:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:theme="#style/AppTheme"
android:id="#+id/actualMainActivity"
tools:context=".ActualMainActivity"
><Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add new noob"
android:id="#+id/addNewNoob"
android:layout_marginLeft="33dp"
android:layout_marginStart="33dp"
android:onClick="addNewNoob"
android:layout_alignTop="#+id/listOfNoobs"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" /></RelativeLayout>
the method inside my java class (ActualMainActivity) was like this:
public void addNewNoob(View view) {
Log.i("Tag", "you clicked the add button");
}
Only after I've implemented the Parse SDK to work with, my Gradle resynced and now when I run the application I get the 'Method not found exception'.
I would like to point out that when I assign an onClickListener directly to the button like this:
final Button a = (Button) findViewById(R.id.addNewNoob);
a.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Log.i("Tag", "you clicked the add button");
}
});
that works perfectly fine...
What have I changed when I installed the SDK ?
How can I get back to the way that I write the methods on XML and they are executed accordingly.
Really confused... thanks in advance
here's the logcat:
02-09 11:29:34.917 2669-2669/com.example.shaked.sqliteexample02 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.shaked.sqliteexample02, PID: 2669
java.lang.IllegalStateException: Could not find a method listOfNoobs(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.Button with id 'listOfNoobs'
at android.view.View$1.onClick(View.java:3994)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NoSuchMethodException: listOfNoobs [class android.view.View]
at java.lang.Class.getMethod(Class.java:664)
at java.lang.Class.getMethod(Class.java:643)
at android.view.View$1.onClick(View.java:3987)
Thanks in advance
Create a New Project move the old Classes to the New one and Check!
its giving methodexception error
so see to it that the method named listofnoobs() is not missing.
also clean your project and then rebuild it