Failed to convert #drawable/ into a drawable - android

I have added an image to my Android project which I want to use in the UI. I have added the file my-image.png to the drawable directory (to all 4 drawable directories created with the project), and added the ImageView to the layout:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/textView"
android:layout_marginBottom="63dp"
android:src="#drawable/my-image" />
The problem is that I get the following error:
Rendering Problems
Failed to convert #drawable/my-image into a drawable
This is the capture:
Additionaly, if I try to compile the project, I get the following error:
Gradle: Execution failed for task ':MyProject:processDebugResources'.
Why do I get these errors and how can I solve it? Am I missing something? I've just started Android development.

Gradle: Execution failed for task ':MyProject:processDebugResources'.
because you have naming convention error in Resources
file name: must contain only [a-z0-9_.]
Rename file name to my_image

Rename this drawable #drawable/my-image to #drawable/my_image

Try using underscore and small characters in file name, for example
my_image.png

Try To use only abc...xyz and 0123...9, dont use -, instead use _(underscore).
Use my_name instead of my-name, because Hyphens(-) have a special meaning in coding, so it cant be use literally with strings.

If the naming convention is correct try:
Open up resources dialog and see if image png preview is displayed.
Select image in design view > Go to properties > Click the ellipsis button > Drawable > Search for your png image and click on it.
If the preview is not displayed cancel out of resources, and try resaving the image again in png format.
This example uses photoshop CS2. Open image in photoshop and select Files > Save For Web > Click Save. (Do not use File > Save As)

It worked for me you should not include special characters only alphabets

Related

Error while loading gif image source

I tried executing the following line to load gif image, programatically.
gifInputStream = context.getResources().openRawResource(R.drawable.image);
But, studio used to indicate an error near "R.drawable.image".
I found a solution, or rather hack around to my issue. I just added "+" symbol. So, the line looks like this now...
gifInputStream = context.getResources().openRawResource(+R.drawable.image);
AndroidStudio doesn't show any error now.
it required raw file not drawable.
Please create res/raw/ directory and move your file in the raw directory.
after then:-
context.getResources().openRawResource(R.raw.yourfilename)

I have no clue as how to set string path

I am using a third party library for splash screen. I got it from https://github.com/ViksaaSkool/AwesomeSplash. I have followed the whole tutorial but i am getting error while setting string path. It has a line
"configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO); //set path String". Android studio is unable to resolve DROID_LOGO and i am getting error. I replaced DROID_LOGO with DATA and got this error.
As suggested on the post i have written this code.
public class splashex extends AwesomeSplash {
//DO NOT OVERRIDE onCreate()!
//if you need to start some services do it in initSplash()!
#Override
public void initSplash(ConfigSplash configSplash) {
/* you don't have to override every property */
//Customize Circular Reveal
configSplash.setBackgroundColor(R.color.colorPrimary); //any color you want form colors.xml
configSplash.setAnimCircularRevealDuration(2000); //int ms
configSplash.setRevealFlagX(Flags.REVEAL_RIGHT); //or Flags.REVEAL_LEFT
configSplash.setRevealFlagY(Flags.REVEAL_BOTTOM); //or Flags.REVEAL_TOP
//Choose LOGO OR PATH; if you don't provide String value for path it's logo by default
//Customize Logo
configSplash.setLogoSplash(R.mipmap.ic_launcher); //or any other drawable
configSplash.setAnimLogoSplashDuration(2000); //int ms
configSplash.setAnimLogoSplashTechnique(Techniques.Bounce); //choose one form Techniques (ref: https://github.com/daimajia/AndroidViewAnimations)
//Customize Path
configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO); //set path String(**I am getting error here**)
// configSplash.setOriginalHeight(400); //in relation to your svg (path) resource
configSplash.setOriginalWidth(400); //in relation to your svg (path) resource
configSplash.setAnimPathStrokeDrawingDuration(3000);
configSplash.setPathSplashStrokeSize(3); //I advise value be <5
configSplash.setPathSplashStrokeColor(R.color.colorPrimaryDark); //any color you want form colors.xml
configSplash.setAnimPathFillingDuration(3000);
configSplash.setPathSplashFillColor(R.color.colorPrimaryDark); //path object filling color
//Customize Title
configSplash.setTitleSplash("My Awesome App");
configSplash.setTitleTextColor(R.color.colorAccent);
configSplash.setTitleTextSize(30f); //float value
configSplash.setAnimTitleDuration(3000);
configSplash.setAnimTitleTechnique(Techniques.FlipInX);
configSplash.setTitleFont("fonts/myfont.ttf"); //provide string to your font located in assets/fonts/
}
#Override
public void animationsFinished() {
//transit to another activity here
//or do whatever you want
}
}
The error i am getting is
java.lang.RuntimeException: Font asset not found fonts/myfont.ttf
at android.graphics.Typeface.createFromAsset(Typeface.java:190)
I searched various links and all suggested to add assets folder but i dont know where to make assets folder and what to store in that.
please help me with all the details about assets and fonts.
Still i am getting this.
You have to create folder named fonts according to the following path:
your_android_project_folder > app > src > main > assets > fonts
Now within your fonts folder,you need to store your myfont.ttf file.
I had the same problem and here is how I solved it :
For the missing DROID_LOGO, you can rewrite the line from this:
configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO);
to this :
configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO);
Here, make sure you add to your project the Constants.java class which can be found here
And for the missing font, go to the line
configSplash.setTitleFont("fonts/myfont.ttf"); //provide string to your font located in assets/fonts/
and replace myfont.ttf with another font present in your assets/font folder for example fonts/diti_sweet.ttf(which can be found on the AwesomeSplash repository) and averything might work fine
Comment out this line:
configSplash.setPathSplash(SyncStateContract.Constants.DROID_LOGO);
and rename myfont.ttf to your font in folder assets.

Meteor run android-device failing: How to correctly define launchScreens

Trying to change the default splash screen on my meteor app. Running meteor run android-device produces a long error message (see relevant section below).
From what I gather, it seems the three nine patch files are being referenced twice...but I have no idea how to de-reference them.
The app worked before I added the following to my mobile-config.js and added the actual image files. Commenting out the three android lines does not help. Deleting the nine patch files will also not help.
App.launchScreens({
'android_xhdpi_portrait':'splash/xhdpi.9.png',
'android_hdpi_portrait':'splash/hdpi.9.png',
'android_mdpi_portrait':'splash/mdpi.9.png',
'ipad_portrait_2x':'splash/ipad_portrait_2x.png',
'ipad_portrait':'splash/ipad_portrait.png',
'iphone_2x':'splash/iphone_2x.png',
'iphone5':'splash/iphone5.png',
'iphone6':'splash/iphone6.png',
'iphone6p_portrait':'splash/iphone6p_portrait.png'
});
I'm quite sure the images only exist in the directory once. I know the path is correct because the ios splash images work perfectly.
Here is the relevant piece of console output:
res/drawable-port-mdpi-v4/screen.png:0: error: Resource entry screen is
already defined.
res/drawable-port-mdpi-v4/screen.9.png:0: Originally defined
here.
res/drawable-port-hdpi-v4/screen.png:0: error: Resource entry screen is
already defined.
res/drawable-port-hdpi-v4/screen.9.png:0: Originally defined
here.
res/drawable-port-xhdpi-v4/screen.png:0: error: Resource entry screen is
already defined.
res/drawable-port-xhdpi-v4/screen.9.png:0: Originally defined here.
The meteor docs state:
For Android, launch screen images should be special "Nine-patch" image files that specify how they should be stretched.
The Android docs state (in relation to nine patch files):
It must be saved with the extension .9.png...
I used the nine patch generator here (googlecode.com) that automatically takes a .png and outputs .9.png files.
However, using the .9.png file extension was the issue here. For some reason, the cordova/meteor build process did not handle files already in .9.png format.
Final answer: If using a .9.png generator, rename the files to just .png before adding them to your meteor project.

No resource found that matches #drawable/test err android studio

I've tried all solutions. Finally decided to post this question.
The situation is as follows:
My drawable has test.png image which I use in my project.
In eclipse it works perfectly but in Android Studio it doesn't work.
Also I'm not getting any compiler error.
I am getting only this type of error almost 54 times when cradle build. As this image is set of as background to 54 screens. :(
What could be the problem?
You should remove the extension part.
For example if your image is called mimg.png in your
resource files you should access it via #drawable/mimg.
Edit
If in eclipse is fine, then create the project new and add file by file. I also had this issues and after some tries ai gave up and created new and after added file by file.
As an alternative please check if you add it in other drawables folders.
That's it.
You need to reference your drawable without the extension: Like this:
android:src="#drawable/test"
Remove the image extension from your xml file and try that please!

I have there is no resources error in my xml file

I have an Android xml file that added to create a splash, for this splash I uploaded a image and set xxhdpı, xhddi, mdpı, hdpı formats from nine patch then I added each one to each format (I mean xxhdpı to xxhdpı format and mdpı to mdpı format folder under resources) then it gives an error
no resources found the given name(at backround with value '#drawable tesbihsplashh.9.png'
Set Background image like:
android:background="#drawable/tesbihsplashh"
Make sure tesbihsplashh.png image avialable into your drawable folder.

Categories

Resources