我试图使用内部存储中的文件填充listview,但每次我都会收到错误。这是我的代码:
public class ReminderListActivity extends ListActivity {
private static final int ACTIVITY_CREATE = 0;
ListView listSavedFiles;
String[] SavedFiles;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_reminder_list);
listSavedFiles = (ListView) findViewById(R.id.sampleList);
ShowSavedFiles();
}
void ShowSavedFiles() {
SavedFiles = getApplicationContext().fileList();
ArrayAdapter<String> adapter
= new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
SavedFiles);
listSavedFiles.setAdapter(adapter);
}
}
错误:
java.lang.OutOfMemoryError: Failed to allocate a 16000012 byte allocation
with 4194304 free bytes and 14MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
at android.content.res.Resources.loadDrawable(Resources.java:2540)
at android.content.res.Resources.getDrawable(Resources.java:806)
at android.app.ApplicationPackageManager.getDrawable(ApplicationPackageManager.java:836)
at android.app.ApplicationPackageManager.loadUnbadgedItemIcon(ApplicationPackageManager.java:2068)
at android.app.ApplicationPackageManager.loadItemIcon(ApplicationPackageManager.java:2048)
at android.content.pm.PackageItemInfo.loadIcon(PackageItemInfo.java:155)
at android.content.pm.ComponentInfo.loadDefaultIcon(ComponentInfo.java:184)
at android.app.ApplicationPackageManager.loadUnbadgedItemIcon(ApplicationPackageManager.java:2071)
at android.app.ApplicationPackageManager.loadItemIcon(ApplicationPackageManager.java:2048)
at android.content.pm.PackageItemInfo.loadIcon(PackageItemInfo.java:155)
at com.android.systemui.recents.misc.SystemServicesProxy.getActivityIcon(SystemServicesProxy.java:494)
at com.android.systemui.recents.model.RecentsTaskLoader.getAndUpdateActivityIcon(RecentsTaskLoader.java:407)
at com.android.systemui.recents.model.RecentsTaskLoadPlan.executePlan(RecentsTaskLoadPlan.java:238)
at com.android.systemui.recents.model.RecentsTaskLoader.loadTasks(RecentsTaskLoader.java:477)
at com.android.systemui.recents.Recents$TaskStackListenerImpl.run(Recents.java:142)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
我甚至没有任何占用内存的文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<Button
android:layout_width="52dp"
android:layout_height="wrap_content"
android:text="Add"
android:onClick="onClickSave"
android:id="@+id/button3"
android:layout_gravity="right" />
<ListView
android:layout_width="465dp"
android:layout_height="wrap_content"
android:id="@+id/sampleList"
android:layout_gravity="center_horizontal" />
</LinearLayout>