我想在幻灯片放映上制作带有不同图像的应用,我的代码如下:
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.swipe, container, false);
ImageView imageView = view.findViewById(R.id.swipe_imageView);
TextView textView = view.findViewById(R.id.swipe_textView);
if (CustomAdapterList.titleForOther.equalsIgnoreCase("Vers la lune"))
{
imageView.setImageResource(vers[position]);
}
else {
imageView.setBackgroundResource(image[position]);
}
textView.setText(CustomAdapterList.titleForOther + "");
container.addView(view);
return view;
}
当我运行我的应用程序并点击“Vers la lune”标题我的应用程序崩溃并且错误说:
java.lang.OutOfMemoryError: Failed to allocate a 298650252 byte allocation with 12571136 free bytes and 238MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
和错误来自这一行:
imageView.setImageResource(vers[position]);
我的清单代码如下:
<application
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="false"
android:theme="@style/AppTheme"
android:largeHeap="true">
这可能会奏效。加上这个
android:largeHeap="true"
在您的Manifest.xml文件中。在应用程序标签。