当我尝试包含操作栏以设置活动标题时,我的应用程序会抛出内存不足错误。不幸的是,这些活动包含要显示的图像。我如何克服这个问题来为活动添加标题,同时在同一活动中显示图像。我已经处理了 Manifest 和 activity.xml 中的所有其他内容以显示标题。下面是代码。
public class ScanActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_scan);
ActionBar actionBar=getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle("Preview");
actionBar.setDisplayShowTitleEnabled(true);
这是错误:
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:683)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:513)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:889)
at android.content.res.Resources.loadDrawable(Resources.java:3080)
at android.content.res.Resources.getDrawable(Resources.java:1627)
at com.android.internal.widget.ActionBarView.setIcon(ActionBarView.java:1037)
at com.android.internal.policy.impl.PhoneWindow.setDefaultIcon(PhoneWindow.java:1550)
at android.app.Activity.initActionBar(Activity.java:2017)
at android.app.Activity.setContentView(Activity.java:2032)
at com.example.kittu.ClientLync.ScanActivity.onCreate(ScanActivity.java:69)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$900(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)