1
When inserting a ImageView
, and try to run the app on the emulator, it displays the following message on the screen: **com.android.phone has stopped**
, but that message disappears and it performs normally.
But when I run on mobile, it shows the following error:
Caused by: android.content.res.Resources$Notfoundexception: Resource ID #0x7f060056
then closes the application.
*************************** XML **********************************************
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:text="Aposte na sua sorte!"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
"
android:textStyle="bold"
android:typeface="normal"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:onClick="sortearNumero"
android:text="Jogar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<TextView
android:id="@+id/textoResultado"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="316dp"
android:layout_marginTop="32dp"
android:text="Nenhum numero selecionado"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.507"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.504"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textoResultado"
app:srcCompat="@drawable/img_principal" />
************************* JAVA ***************************************
package com.example.jordansilva.sorteio;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void sortearNumero(View view) {
TextView textoResultado = findViewById(R.id.textoResultado);
int x = new Random().nextInt(61);
textoResultado.setText("O numero sorteado foi: " + x);
}
}
If you take Imageview it works normal ? Are you setting and calling this element somewhere ? Post your code to see better.
– rbz
Yes, if I take Imageview it works. I will post the XML code and the java for you to see.
– Jordan