我正在開發導遊應用程序。我正在使用鰭狀圖像查看圖像。我已解碼位圖。但它仍然給出了outofmemoryError。請幫我解決一下這個。由於事先OutOfMemory錯誤即使大位圖有效處理
10月9日至1日:30:47.595:E/AndroidRuntime(30992):致命異常:主
10月9日至1日:30:47.595:E/AndroidRuntime(30992): 了java.lang.RuntimeException:無法啓動活動 ComponentInfo {com.isuru.allaboutkataragama/com.isuru.allaboutkataragama.Thissa}: android.view.InflateException:二進制XML文件行#63:錯誤 充氣類
09-01 10:30:47.595:E/AndroidRuntime(30992):在 android.app.ActivityThread .performLaunchActivity(ActivityThread.java:2295)
10月9日至1日:30:47.595:E/AndroidRuntime(30992):在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
09 -01 10:30:47.595:E/AndroidRuntime(30992):在 android.app.ActivityThread.access $ 700(ActivityThread.java:159)
10月9日至1日:30:47.595:E/AndroidRuntime(30992 ):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1316)
09-01 10:30:47.59 5:E/AndroidRuntime(30992):在 dalvik.system.NativeStart.main(本地方法)09-01 10:30:47.595: E/AndroidRuntime(30992):引起:android.view.InflateException: 二進制XML文件行#63:錯誤充氣類
十月9日至1日:30:47.595:E/AndroidRuntime(30992):在 android.view.LayoutInflater.createView(LayoutInflater.java:626)
09 -01 10:30:47.595:E/AndroidRuntime(30992):在 com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
1月9日至一日0:30:47.595:E/AndroidRuntime(30992):在 android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
10月9日至一日:30:47.595:E/AndroidRuntime(30992):在 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
10月9日至1日:30:47.595:E/AndroidRuntime(30992):在 android.view.LayoutInflater.rInflate(LayoutInflater.java:761 )
10月9日至1日:30:47.595:E/AndroidRuntime(30992):在 android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
10月9日至1日:30:47.595:E/AndroidRuntime(30992):在 android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
10月9日至1日:30:47.595:E/AndroidRuntime(30992):在 android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
10月9日至1日:30:47.595:E/AndroidRuntime(30992):在 機器人。view.LayoutInflater.rInflate(LayoutInflater.java:769)
10月9日至一日:30:47.595:E/AndroidRuntime(30992):在 android.view.LayoutInflater.inflate(LayoutInflater.java:498)
10月9日至一日:30:47.595:E/AndroidRuntime(30992):在 android.view.LayoutInflater.inflate(LayoutInflater.java:398)
10月9日至一日:30:47.595:E/AndroidRuntime (30992):at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
09-01 10:30:47.595:E/AndroidRuntim E(30992):在 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:361)
十月9日至1日:30:47.595:E/AndroidRuntime(30992):在 機器人.app.Activity.setContentView(Activity.java:1956)
10月9日至1日:30:47.595:E/AndroidRuntime(30992):在 com.isuru.allaboutkataragama.Thissa.onCreate(Thissa.java:83 )
10月9日至1日:30:47.595:E/AndroidRuntime(30992):產生的原因: java.lang.reflect.InvocationTargetException
10月9日至1日:30:47.595:E/AndroidRuntime(30992):在 java.lang.reflect.Constructor.constructNative(本機方法)
10月9日至1日:30:47.595:E/AndroidRuntime(30992 ):在 java.lang.reflect.Constructor.newInstance(Constructor.java:417)
10月9日至1日:30:47.595:E/AndroidRuntime(30992):在 android.view.LayoutInflater.createView( LayoutInflater.java:600)
十月九日至一日:30:47.595:E/AndroidRuntime(30992):產生的原因: java.lang.OutOfMemoryError
10月9日至一日:30:47.595:E/AndroidRuntime(30992):在 android.graphics.BitmapFactory.nativeDecodeAsset(本機方法)
10月9日至一日:30:47.595:E/AndroidRuntime(30992) :在 android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
10月9日至1日:30:47.595:E/AndroidRuntime(30992):在 android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java :444)
09-01 10:30:47.595:E/AndroidRuntime(30992):at android.graphics.drawable.Drawable.createFromResou rceStream(Drawable.java:832)
10月9日至1日:30:47.595:E/AndroidRuntime(30992):在 android.content.res.Resources.loadDrawable(Resources.java:2988)
10月9日至1日:30:47.595:E/AndroidRuntime(30992):在 android.content.res.TypedArray.getDrawable(TypedArray.java:602)
10月9日至1日:30:47.595:E/AndroidRuntime (30992):at android.widget.ImageView。(ImageView.java:131)09-01 10:30:47.595:E/AndroidRuntime(30992):at android.widget.ImageView。(ImageView。java:121)
這是我的代碼。
iv1=(ImageView) findViewById(R.id.imgvw_thissa1);
iv2=(ImageView) findViewById(R.id.imgvw_thissa2);
iv3=(ImageView) findViewById(R.id.imgvw_thissa3);
iv4=(ImageView) findViewById(R.id.imgvw_thissa4);
iv5=(ImageView) findViewById(R.id.imgvw_thissa_lake);
iv1.setImageBitmap(
decodeSampledBitmapFromResource(getResources(), R.drawable.tissamaharama, 400, 400));
iv2.setImageBitmap(
decodeSampledBitmapFromResource(getResources(), R.drawable.thissa2, 275, 183));
iv3.setImageBitmap(
decodeSampledBitmapFromResource(getResources(), R.drawable.thissa3, 400, 400));
iv4.setImageBitmap(
decodeSampledBitmapFromResource(getResources(), R.drawable.thissa7, 400, 400));
iv5.setImageBitmap(
decodeSampledBitmapFromResource(getResources(), R.drawable.thissalake, 400, 400));
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float)height/(float)reqHeight);
} else {
inSampleSize = Math.round((float)width/(float)reqWidth);
}
}
return inSampleSize;
}
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
'機器人.view.InflateException:二進制XML文件行#63:錯誤與您的xml文件膨脹類問題。 – 2014-09-01 05:52:45