I'm kinda new to android development and having problem showing images from my drawable resource file with java code. I simplified my original app to isolate the problem, so now it is just a blank activity with one image view in the center.
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView000"
android:layout_width="82dp"
android:layout_height="82dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
public class MainActivity extends AppCompatActivity {
public ImageView images;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onStart() {
super.onStart();
images = findViewById(R.id.imageView000);
images.setImageResource(R.drawable.imageNameInDrawableFile);
}
}
There is no error in compilation. But when I run this on the virtual device or my phone, the app crashes on start. What's wrong?
Update: thank for the tips everyone. the problem was the directory of the image, it was "E:\AndroidStudioProjects\TestApplication\app\src\main\res\drawable-v24", just removed the "-v24" in directory shown after i drop myImage into drawable folder and it worked perfectly after.