我在這裏閱讀了其他一些關於類似問題的線索,但它沒有解決我的問題。285692020字節分配/位圖工廠問題的內存不足?
所以我的應用程序,它根據用戶的微調器選擇更改圖像。因此它從sharedPreferences文件加載選擇。
問題是,此代碼適用於我幾個月前製作的應用程序。我正在重新編寫我的應用程序,但需要時使用舊應用程序中的代碼。該代碼是相同的,適用於我的舊應用程序,但不是我的新應用程序。這是我的錯誤日誌:
DivXPlugin::onOpenDecryptSession() Not a Divx File.
PrGenericPlugin::onOpenDecryptSession() onCanHandle error
Error: ACDB AudProc vol returned = -8
E/MP-Decision(1802): num online cores: 1 reqd : 2 available : 4 rq_depth:7.000000 hotplug_avg_load_dw: 46
E/MP-Decision(1802): UP cpu:1 core_idx:1 Nw:1.900000 Tw:140 total_time_up:147.000000
E/AudioResampler(209): Unsupported sample format, 1 bits, 2 channels
E/dalvikvm-heap(26650): Out of memory on a 285692020-byte allocation.
E/AndroidRuntime(26650): FATAL EXCEPTION: main
E/AndroidRuntime(26650): java.lang.OutOfMemoryError
E/AndroidRuntime(26650): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
E/AndroidRuntime(26650): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
E/AndroidRuntime(26650): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
E/AndroidRuntime(26650): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:835)
E/AndroidRuntime(26650): at android.content.res.Resources.loadDrawable(Resources.java:2988)
E/AndroidRuntime(26650): at android.content.res.Resources.getDrawable(Resources.java:1558)
E/AndroidRuntime(26650): at com.Chris.App.Info.onCreate(Info.java:34)
E/AndroidRuntime(26650): at android.app.Activity.performCreate(Activity.java:5372)
E/AndroidRuntime(26650): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
E/AndroidRuntime(26650): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
E/AndroidRuntime(26650): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
E/AndroidRuntime(26650): at android.app.ActivityThread.access$700(ActivityThread.java:159)
E/AndroidRuntime(26650): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
E/AndroidRuntime(26650): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(26650): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(27961): FATAL EXCEPTION: main
E/AndroidRuntime(27961): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.Chris.App/com.Chris.App.Info}: java.lang.NullPointerException
E/AndroidRuntime(27961): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2219)
E/AndroidRuntime(27961): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
E/AndroidRuntime(27961): at android.app.ActivityThread.access$700(ActivityThread.java:159)
E/AndroidRuntime(27961): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
E/AndroidRuntime(27961): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(27961): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(27961): at android.app.ActivityThread.main(ActivityThread.java:5419)
E/AndroidRuntime(27961): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(27961): at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime(27961): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
E/AndroidRuntime(27961): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime(27961): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(27961): Caused by: java.lang.NullPointerException
E/AndroidRuntime(27961): at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:174)
E/AndroidRuntime(27961): at com.Chris.App.Info.<init>(Info.java:17)
E/AndroidRuntime(27961): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime(27961): at java.lang.Class.newInstance(Class.java:1130)
E/AndroidRuntime(27961): at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
E/AndroidRuntime(27961): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
E/AndroidRuntime(27961): ... 11 more
E/AndroidRuntime(26650): at android.app.ActivityThread.main(ActivityThread.java:5419)
E/AndroidRuntime(26650): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(26650): at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime(26650): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
E/AndroidRuntime(26650): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime(26650): at dalvik.system.NativeStart.main(Native Method)
E/android.os.Debug(674): [email protected] > sdumpstate -k -t -z -d -o /data/log/dumpstate_app_error
E/EnterpriseContainerManager(674): ContainerPolicy Service is not yet ready!!!
E/ViewRootImpl(674): sendUserActionEvent() mView == null
下面是代碼,這再次,作品在App A,但一個不SNIPPIT應用B ?:
SharedPreferences sharedPreferences = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE);
final ImageView im = (ImageView)findViewById(R.id.selection1);
String s = sharedPreferences.getString("MEM1", "");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.info);
if(s.equals("Nothing Selected")) {
im.setImageDrawable(getResources().getDrawable(R.drawable.clearimage));
im.setVisibility(View.GONE);
} else if(s.equals("Selection 1")) {
im.setImageDrawable(getResources().getDrawable(R.drawable.selection1image));
im.getLayoutParams().height = 600;
im.getLayoutParams().width = 600;
}
}
所以,我似乎得到一個徹頭徹尾的內存錯誤和上下文包裝/問題與我的共享首選項?令人沮喪的代碼是完全一樣的,在我的其他應用程序,它工作正常
您正在嘗試分配285 MB,因此不會感到意外,因爲您將OutOfMemoryError :) –
您正在嘗試加載285 MB圖像。這大約比應用程序允許的內存多10倍。 – kgmaize
Ick !!愚蠢的問題跟進。在Eclipse中創建新的Android應用程序時,我沒有做任何不同的事情。我如何將它設置得更低? – NewGuyChris