Android-studio Project fails to run - android

I'm currently working on a project in android studio and as a part of my project I needed to clean it. I followed the proper steps and now my assignment wont load.
I keep getting these errors and I don't know what they mean. Please help!

Try changing your ImageView definition to:
<ImageView
android:src="#drawable/sundae"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:id="#+id/imageView" />
I don't believe the tag "layout_centerCrop" exists.

The error basically says that the layout attribute mentioned is not identified, or is nonexistent. In this case, it is layout_centerCrop. Please replace android:layout_centerCrop="true" with android:scaleType="centerCrop".
By the way, I would suggest centerInside rather than centerCrop so that none if the image will be cropped out, and will still be in the same aspect ratio.
It will look like this:
<ImageView
android:src="#drawable/sundae"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:id="#+id/imageView" />

Related

Unknown attribute "android:padding"

Since I'm not quite sure when, I'm getting a lint warning when viewing my layout file of "Unknown attribute android:padding"...
The layout file starts:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/widget_margin"
android:id="#+id/widget" >
I'm getting similar warnings for android:layout_alignParentTop etc in the following:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imageView_port"
android:visibility="gone"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
Furthermore, I'm finding now that when an image is loaded into the ImageView that is the correct aspect ratio but not the right pixel size (smaller), the image is being shown in the ImageView at its actual (too small) size rather than being stretched out to fit the ImageView (like it used to do, and like I want it to do).
I'm not sure when these warnings started to appear. And I'm confused because it appears that at least android:padding is still a valid attribute according to the docs.
Other warnings I'm getting include for android:tag... which is also a pretty basic attribute and still "legal" according to the above docs.
So, clean and rebuild did nothing, and Invalidate Caches / Restart also did nothing.
But the following worked:
Close Android Studio
Remove the content of folder C:\Users\MyName\.AndroidStudio3.4\system\caches
Open Android Studio
That's it... not sure why "Invalidate Caches" wouldn't have achieved the same thing... maybe that is clear some other caches.
P.S. didn't solve the "image not being stretched to fit ImageView" but that must be a different issue.

image isnt showing on layout preview in android studio

Am new to app development , however I have seen multiple sources online that show you how to add an image to your layout
However the image isnt being shown on the layout preview
My code is below
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitStart"
app:srcCompat="#drawable/mm"
tools:layout_editor_absoluteX="132dp"
tools:layout_editor_absoluteY="16dp" />
I just don't know what I'm doing wrong .. I've followed multiple guides but still nothing
Image screenshot of studio showing issue :
https://imgwiz.com/image/gzHD
My PC seems to be having issues freezing occasionally whe Android studio is running so am setting up a VPS with studio on it and will test all these suggestions on the new installation as that may be related to my issue
Use
<android.support.v7.widget.AppCompatImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitStart"
app:srcCompat="#drawable/mm"
tools:layout_editor_absoluteX="132dp"
tools:layout_editor_absoluteY="16dp" />
instead of
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitStart"
app:srcCompat="#drawable/mm"
tools:layout_editor_absoluteX="132dp"
tools:layout_editor_absoluteY="16dp" />
helped me.
You can replace it without any changes in your code.
In addition: Be aware of using
tools:layout_editor_absoluteX="132dp"
tools:layout_editor_absoluteY="16dp"
The namespace tools: means that it only affects your editor preview. As i saw in your screenshot, you are using a ConstraintLayout as parent layout. Consider adding app:layout_constraintBottom_toBottomOf etc to align your ImageView.
it seems that your ImageView's position is not in the viewing area of the Design/BluePrint
so I recommend to switch to Text mode
and add these to your ImageView
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp"
to make it show on the designer when move it to your desired position

Image Source not found or ContentDescription is missing

<ImageButton
android:layout_width="fill_parent"
android:layout_height="200dp"
android:id="#+id/imageButton"
android:scaleType="fitCenter"
android:clickable="true"
android:cropToPadding="true"
android:adjustViewBounds="true"
android:src="#drawable/wallhaven_263366"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="65dp"
android:contentDescription="#string/imagebutton" />
this is my code.. and I tried almost every thing I found here...
I've added the image in src but its not showing in either preview or avd. some times it give error of not found src as given
or content description missing.. if I provide a content description and res value then it says could not resolve resource #string/.
any sort of help is welcomed.
Missing content description is not an error.
If you sure the file is in the Drawablr folders try to reneame it and remove the digits. SOmetimes it cause problems when using digits in file name.
Try hitting Ctrl + F9 if you are operating over windows, this will build the project. I have faced similar errors while starting up the studio and after building the project it solves them. And even try removing the extra digits from image name.
Solution :Just edited the image format to png through paint .. earlier I did by renaming it in directory.
//other problem
but still idk why none of the button or image is visible in avd yet I can add remove or edit them in preview mode.
P.S.
they are also not visible in preview just editable

Why the ImageView class is not found?

i'm having troubles with creating the first android app (Silent Toggle Mode from the pdf "Android.Application.Development.for.For.Dummies" ) with inserting an Imageview in the main.xml file, when I go to the graphical layout, the image isn't showing itself and this error appears:"The following classes could not be found:
- ImageView (Change to android.widget.ImageView, Fix Build Path, Edit XML)"
this is my xml code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="#string/hello_world"
android:orientation="vertical"
tools:context=".MainActivity" >
<EditText android:id="#+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<ImageView
android:id="#+id/phone_icon"
android:contentDescription="#string/description"
android:layout_width="wrap_content"
android:scaleType="fitXY"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/phone_on" />
<Button
android:id="#+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ToggleSilentMode" />
</LinearLayout>
thanks
This is one issue that I have also run across recently. It was sort of a misleading error to me and kept me stumped for around 30 minutes this morning. It isn't that Android cannot find the class. It is that it is having trouble importing the image source file.
Now the reason that it is having trouble finding the image is because I did not copy the source image into the directory correctly. I have chosen to drag the source file from another folder directory into the appropriate locations. In the process, it did not copy the file over properly. Or it copied it over as just a link to the other resource.
As a result Android does not know what to do with the resource and throws that odd error. In order to resolve this problem, you need to delete the old image sources and then replace them with direct full copies of their equivalents. Then you should see this error go away and the application working as expected from the xml layout code.
I faced the same problem once. To get it out, I replaced all the existing images, now it worked.
I had the same issue, when added a new ImageView in my xml with an image src.
I tried to open this image with Photoshop and get an "module format error". So the image was corrupted. The problem was solved creating a new image similar to the first one.
Hope it works :)

Problem with the size of the Twitter image

I have used this code to get a feed reader form twitter. I have list them in the listView as the article says, but with some images I have a problem with the size and they are anormally big...I have tried unsuccesfully to fix the size of the image with:
<ImageView android:id="#+id/photoUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="10dp" android:maxHeight="10dp"
android:paddingRight="12dp"/>
Strange that the code didn't do that for me when I wrote it. What android version are you testing on?
For one reason or another, I've found that often only specifying maxWidth/maxHeight doesn't behave as you would expect, and I also have to specify minWidth/minHeight to effectively control image size. I had to do exactly that in a follow-up development tutorial to the post you reference.
Give something like this a try:
<ImageView
android:id="#+id/photoUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="30dip"
android:minWidth="30dip"
android:maxHeight="30dip"
android:minHeight="30dip"
android:paddingRight="12dip" />

Categories

Resources