Android应用程序在启动画面后崩溃 - Android Studio

时间:2014-11-07 20:21:04

标签: android

目前我正在开始构建一个Android应用程序,当我运行它时,它会在启动画面之后崩溃。

这是我的错误:

  

11-07 20:11:55.344 1273-1273 / com.patrickmelia.bcrfm E / AndroidRuntime:FATAL EXCEPTION:main       过程:com.patrickmelia.bcrfm,PID:1273       java.lang.OutOfMemoryError:无法分配带有1569794个空闲字节的603288012字节分配和61MB直到OOM               at dalvik.system.VMRuntime.newNonMovableArray(Native Method)               在android.graphics.BitmapFactory.nativeDecodeAsset(本机方法)               在android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)               在android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)               在android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:973)               在android.content.res.Resources.loadDrawableForCookie(Resources.java:2423)               在android.content.res.Resources.loadDrawable(Resources.java:2330)               在android.content.res.Resources.getDrawable(Resources.java:758)               在android.content.res.Resources.getDrawable(Resources.java:724)               在com.patrickmelia.bcrfm.CustomDrawerAdapter.getView(CustomDrawerAdapter.java:56)               在android.widget.AbsListView.obtainView(AbsListView.java:2344)               在android.widget.ListView.makeAndAddView(ListView.java:1864)               在android.widget.ListView.fillDown(ListView.java:698)               在android.widget.ListView.fillFromTop(ListView.java:759)               在android.widget.ListView.layoutChildren(ListView.java:1673)               在android.widget.AbsListView.onLayout(AbsListView.java:2148)               在android.view.View.layout(View.java:15596)               在android.view.ViewGroup.layout(ViewGroup.java:4966)               在android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:911)               在android.view.View.layout(View.java:15596)               在android.view.ViewGroup.layout(ViewGroup.java:4966)               在android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)               在android.widget.FrameLayout.onLayout(FrameLayout.java:508)               在android.view.View.layout(View.java:15596)               在android.view.ViewGroup.layout(ViewGroup.java:4966)               在com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:494)               在android.view.View.layout(View.java:15596)               在android.view.ViewGroup.layout(ViewGroup.java:4966)               在android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)               在android.widget.FrameLayout.onLayout(FrameLayout.java:508)               在android.view.View.layout(View.java:15596)               在android.view.ViewGroup.layout(ViewGroup.java:4966)               在android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2072)               在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1829)               在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)               在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:5779)               在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:767)               在android.view.Choreographer.doCallbacks(Choreographer.java:580)               在android.view.Choreographer.doFrame(Choreographer.java:550)               在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:753)               在android.os.Handler.handleCallback(Handler.java:739)               在android.os.Handler.dispatchMessage(Handler.java:95)               在android.os.Looper.loop(Looper.java:135)               在android.app.ActivityThread.main(ActivityThread.java:5221)               at java.lang.reflect.Method.invoke(Native Method)               在java.lang.reflect.Method.invoke(Method.java:372)               在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:899)               在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

这是我的活动代码:

public class splashScreen extends Activity {

// Splash screen timer
private static int SPLASH_TIME_OUT = 6000;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splashscreen);

    /*if(!isNetworkAvailable())
    {
        new AlertDialog.Builder(this)
                .setTitle("No Internet Access")
                .setMessage("Whoops, Internet Required. Please connect to the internet and try again")
                .setIcon(android.R.drawable.ic_dialog_alert)
                .show();

    }else{*/

    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            Intent mainIntent = new Intent(splashScreen.this, MainActivity.class);
            splashScreen.this.startActivity(mainIntent);
            splashScreen.this.finish();
        }
    }, SPLASH_TIME_OUT);
}}

有没有人在此之前得到此错误/有人可以帮我解决此错误吗?

2 个答案:

答案 0 :(得分:0)

您应该调整正在布局中加载的图像的大小。此外,制作不同密度的图像将有助于您避免此类问题。

答案 1 :(得分:-1)

我遇到了这个麻烦。您需要可能的解决方案:如果不是强制性的高分辨率,请调整图像大小,或者在应用程序标记的AndroidManifest.xml中写入:

android:largeHeap="true"

第二个为我工作。