My code ran fine on the emulator, however, as soon as I tried running my code on a device (in this case a Nexus 5) I started to get A LOT of Resources.NotFoundExceptions.
(我的代码在模拟器上运行良好,但是,当我尝试在设备(在本例中为Nexus 5)上运行代码时,我开始获得了大量Resources.NotFoundExceptions。)
The majority of the exceptions occur in relation to drawable or color files. (大多数例外情况与可绘制文件或颜色文件有关。)
For example: (例如:)
android.content.res.Resources$NotFoundException: File res/drawable/blob_ocean.xml from drawable resource ID #0x7f060066
Logcat then states that the error is caused by:
(然后,Logcat指出该错误是由以下原因引起的:)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/blob_ocean.xml from drawable resource ID #0x7f060066
then it states that the previous error is caused by:
(然后指出先前的错误是由以下原因引起的:)
Caused by: android.content.res.Resources$NotFoundException: File res/color/radial_pink.xml from color state list resource ID #0x7f04004e
The two examples occur in a fragment on the line with the AnimatedVectorDrawable.
(这两个示例出现在AnimatedVectorDrawable行的一个片段中。)
public class BlobFragment extends Fragment {
private AnimatedVectorDrawable blob;
private ImageView blobView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.blob_fragment, container, false);
blobView = (ImageView) v.findViewById(R.id.blob_o);
blob = (AnimatedVectorDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.blob_ocean, null);
blobView.setImageDrawable(blob);
blob.start();
return v;
}
}
(})
The layout for the fragment looks like this:
(片段的布局如下所示:)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".OceanThemeActivity">
<ImageView
android:id="@+id/blob_o"
android:layout_width="300dp"
android:layout_height="300dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:srcCompat="@drawable/blob_ocean"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.271"/>
</androidx.constraintlayout.widget.ConstraintLayout>
I have looked online but have not been able to find something that works.
(我在网上看过,但找不到有效的方法。)
Having a hard time identifying the issue as everything is working fine in an emulator. (由于在模拟器中一切正常,因此很难识别问题。)
ask by Kübra Uzun translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…