App not working in android studio - android

I have made my first hello world program in android studio and when I launched for the first time (without any images), it was working . But when I put a photo using imageview then when I created the apk it doesn't run saying that the app has stopped working.
following is the code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.himan.helloworld1.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello Himan"
/>
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:text="From Rakesh"
/>
<ImageView
android:src="#drawable/happy_birthday"
android:layout_width="500dp"
android:layout_height="500dp" />
</RelativeLayout>

You can see Video tutorial here
Android Hello World Example
Android Tutorial For Beginners - https://youtu.be/-Cfl6BdLT5K

Related

Android Studio: "Cannot perform refactoring. This element cannot be renamed"

I would like to change the name of the graphics, but android studio shows an error:
"Cannot perform the refactoring. This element cannot be renamed"
On the left is a tutorial on where it works, and on the right my code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/name_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/name"
android:textAlignment="center"
style="#style/NameStyle" />
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/btn_star_big_on"
/>
</LinearLayout>
Refactor works only in the id window:
Why doesn't it work in XML code?
This is the first project on Kubuntu 20.04 LTS.
You are trying to rename a built in drawable of the android platform while the tutorial screenshot you posted is trying to rename the id of the view
What I mean is
The resources having the #android: as prefix are the ones that are built in the android platform and thus can't be refactored or renamed and your screenshot is trying to rename like so. You can see the dialog title Rename xyz and its occurence to which indicates what element you are trying to rename
<ImageView
android:id="#+id/imageView" // This is being changed in the screenshot
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/btn_star_big_on" // You are trying to change this

Text color is changing in Android Studio but not showing on phone

I have browsed through a few places but can't find anything "exact" to solve my issue. I set code in Android Studio and the display showed my top text as orange and the bottom text as blue...which is what I intended. When I tried running it on my phone, the text color did not show as it does in Android Studio. (Just is gray text on my phone)
This is a simple bit of code as I'm currently learning from Udacity and a couple other places. Any ideas why code would show as working on Android Studio but wouldn't work on the phone? (especially when dealing with something as simple as text color?)
The code is as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.saoiray.happybirthday.MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="I'm awesome! Birth of a developer (^_^)"
android:textColor="#FF5722"
android:textSize="32sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Oh yeah, Stephen is awesome!"
android:textColor="#3F51B5"
android:textSize="32sp" />
<ImageView
android:id="#+id/androidparty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:src="#drawable/androidparty"
tools:ignore="ContentDescription" />
</RelativeLayout>
I had the same problem, and i disabled the "High contrast fonts" from the Settings-> Display -> Visibility enhancements , of the phone and now the textColor appears like in Virtual Device

Images does not shown on Mvx.MvxImageView (Android)

I am trying to learn mvvmcross and I am a newbie now. I started to watch N + 1 days of MvvmCross video series and I am stuck at N = 2 Kittens and Lists. I add DownloadCashPlugin and FilePlugin to the project and create Mvx.MvxImageView as shown on the video but when I start my app(both simulator and android device), everything is same but images does not shown or not downloaded. I open permission from android manifest and I have an internet connection on my android device. I am pretty sure I follow videos carefully and dont miss any part.
I am using Visual Studio 2013 Communtiy Edition and MvvmCross is last updated version. I will be glad if anyone can help me on this problem. Thank you.
Item_Kitten.axml ;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Mvx.MvxImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_margin="10dp"
local:MvxBind="ImageUrl ImageUrl" />
<LinearLayout
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:textSize="40dp"
local:MvxBind="Text Name" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
local:MvxBind="Text Price" />
</LinearLayout>
</LinearLayout>

Android TextView top image not rendering properly on 2.3

When I run my android application in Android version >=4 I got this out put(I didn't tested in android version 3):
When run the same application in android version 2.3 I got a bit different output:
You can see in second screenshot the image for about button is not visible. But when I try run the same application several times on 2.3 some times I got about image visible.Here is my code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/actionbar_with_right_button" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:scrollbars="none" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:drawablePadding="#dimen/settings_text_view_drawable_padding"
android:drawableTop="#drawable/snooze_button"
android:gravity="center"
android:onClick="showRemainderSnoozeSettings"
android:padding="#dimen/settings_text_view_padding"
android:text="#string/snooze" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:drawablePadding="#dimen/settings_text_view_drawable_padding"
android:drawableTop="#drawable/help_button"
android:gravity="center"
android:onClick="showFaq"
android:padding="#dimen/settings_text_view_padding"
android:text="#string/help" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:drawablePadding="#dimen/settings_text_view_drawable_padding"
android:drawableTop="#drawable/about_button"
android:gravity="center"
android:onClick="showAbout"
android:padding="#dimen/settings_text_view_padding"
android:text="#string/about" />
</LinearLayout>
</ScrollView>
I didn't understand why this is happening.
Can anyone help me to solve this issue.
Edit :
One more important thing I forgot to mention when I changed android:drawableTop="#drawable/about_button" to android:drawableTop="#drawable/help_button" of about TextView. It worked perfectly. So it can be an issue of my about_button image. So I recreated the about image again and put in all drawable folder. Even after that also I didn't get any +ve result. This issue only in 2.3 or less.
Thanks
May this help you:
Seems like this is a bug with android, where sometimes the first image in the drawable folder doesn't get displayed.....
I had a similar bug - a particular drawable was not being displayed, no matter in what ImageView. So I Added a dummy image called aaaa.png to the drawable folder and problem was solved....

Don't changes layout in android application

I changed in eclipse background of layout and added new view (button).
I started my application but in emulator nothing changed!
What can I make? Mayby it's an Eclipse bug?
I downloaded this project from internet. Initially it had black background.
I added new View - all was OK.
But after I started changed background - and appeared this bugs
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<EditText
android:id="#+id/txtInd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
Whenever you want to test the app again, DO NOT click on your app's icon in the emulator. However, select your project, and click on
IF this doesn't work. Try cleaning your project from : Project >>> Clean

Categories

Resources