Ao tentar executar o app, após implementar o bind dos dados, obtive a seguinte exception:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.alura.stonertrip/com.alura.stonertrip.ui.activity.PackageOverviewActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:246)
at android.content.res.Resources.getDrawableForDensity(Resources.java:982)
at android.content.res.Resources.getDrawable(Resources.java:922)
at android.content.res.Resources.getDrawable(Resources.java:897)
at br.com.alura.stonertrip.utils.ResourcesUtil.getDrawable(ResourcesUtil.java:16)
at com.alura.stonertrip.ui.activity.PackageOverviewActivity.onCreate(PackageOverviewActivity.java:31)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
Aparentemente o erro foi acionado ao executar o método getDrawable(), no ResourcesUtil e passando o ID do Drawable.
Abaixo o trecho de código do Resourcesutil:
public class ResourcesUtil {
public static final String DRAWABLE = "drawable";
public static Drawable getDrawable(Context context, String textDrawabble) {
Resources resources = context.getResources();
int drawableId = resources.getIdentifier(textDrawabble, DRAWABLE, context.getPackageName());
return resources.getDrawable(drawableId);
}
}
E, por fim, o trecho na activity ResumoPacoteActivity a partir do qual o ResourcesUtil é chamado:
Package packageSP = new Package("São Paulo", "package_overview_image", 2, new BigDecimal("243.99"));
TextView place = findViewById(R.id.package_overview_place);
place.setText(packageSP.getLocal());
**Drawable imageDrawable = ResourcesUtil.getDrawable(this, packageSP.getImagem());
ImageView image = findViewById(R.id.package_overview_image);
image.setImageDrawable(imageDrawable);**
Obrigado desde já!