Reputation: 511
I am learning android app development.So while I was building a simple app to show two images on the screen,I have used ImageView.The images are displayed in the android studio design screen,but when I am trying to run the app using the genymotion emulator,the screen is just blank.I am not able to see the images.here is the xml file.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="showmebioapp.studio.com.showmebio.MainActivity"
android:background="@android:color/holo_blue_bright">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/vegeta"
android:layout_marginTop="32dp"
android:id="@+id/imageVegetaId"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/imageGokuId"
android:layout_alignEnd="@+id/imageGokuId"
android:layout_marginRight="32dp"
android:layout_marginEnd="32dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/goku"
android:layout_marginBottom="79dp"
android:id="@+id/imageGokuId"
android:layout_marginLeft="62dp"
android:layout_marginStart="62dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
MAIN ACTIVITY.JAVA
public class MainActivity extends Activity implements View.OnClickListener {
private ImageView vegetaImage;
private ImageView gokuImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vegetaImage=(ImageView)findViewById(R.id.imageVegetaId);
gokuImage=(ImageView)findViewById(R.id.imageGokuId);
vegetaImage.setOnClickListener(this);
gokuImage.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.imageVegetaId:
Intent vegetaIntent=new Intent(MainActivity.this,DetailsActivity.class);
vegetaIntent.putExtra("vegetaBio","hello from vegeta");
startActivity(vegetaIntent);
break;
case R.id.imageGokuId:
Intent gokuIntent=new Intent(MainActivity.this,DetailsActivity.class);
gokuIntent.putExtra("gokuBio","hello from goku");
startActivity(gokuIntent);
break;
}
}
}
Please Help me in finding me the solution.
Upvotes: 6
Views: 13909
Reputation: 81
Just went through this issue for <1 hour - download and try a different emulator and check it. That was my fix after trying the tips mentioned above!
Upvotes: 2
Reputation: 1221
You are using srcCompat instead of using src just like using back goku instead of goku
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:src="@drawable/vegeta"
android:layout_marginTop="32dp"
android:id="@+id/imageVegetaId"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/imageGokuId"
android:layout_alignEnd="@+id/imageGokuId"
android:layout_marginRight="32dp"
android:layout_marginEnd="32dp" />
as it srcCompat attribute is actually defined within AppCompat library.
Important you will need to add appropriate namespace for this.
xmlns:app="http://schemas.android.com/apk/res-auto"
Important
what you are getting it seems like it is just a lint error that can be ignored. I have tried and have the same error, but it is working correctly.for more info
Happy coding :)
Upvotes: 15