gpt4 book ai didi

java - 应用程序停止工作

转载 作者:行者123 更新时间:2023-12-01 17:55:00 25 4
gpt4 key购买 nike

我就是不知道我做错了什么。我是编码的初学者,所以不要生气:)

基本上我想在我的启动屏幕中制作动画背景。但每次启动该应用程序都会停止工作。

这是代码和错误:

欢迎 Activity (启动画面):

public class WelcomeActivity extends AppCompatActivity {

private static int SPLASH_TIME_OUT = 4000;


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

android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.hide();



ImageView bgAni = (ImageView) findViewById(R.id.imageBG);
bgAni.setBackgroundResource(R.drawable.animation_list);

AnimationDrawable pro = (AnimationDrawable) bgAni.getBackground();
pro.start();


new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent welcomeIntent = new Intent(WelcomeActivity.this, MainActivity.class);
startActivity(welcomeIntent);
finish();
}
}, SPLASH_TIME_OUT);

}
}

主要 Activity :

public class MainActivity extends AppCompatActivity {

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

欢迎 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="de.procre.togetheraware.WelcomeActivity">

<ImageView
android:id="@+id/imageBG"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/animation_list"
android:scaleType="fitXY"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="@color/pure_white"/>


</RelativeLayout>

动画列表:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/anim_background" android:oneshot="true">
<item android:drawable="@drawable/frame0000" android:duration="30" />
<item android:drawable="@drawable/frame0001" android:duration="30" />
.
.
.
<item android:drawable="@drawable/frame0124" android:duration="30" />

</animation-list>

错误代码:

08-18 12:45:41.171 13517-13517/de.procre.togetheraware E/AndroidRuntime: FATAL EXCEPTION: main                                                                        
Process: de.procre.togetheraware, PID: 13517
java.lang.OutOfMemoryError: Failed to allocate a 6350412 byte allocation with 4120384 free bytes and 3MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:620)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:455)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1155)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:720)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
at android.content.res.Resources.loadDrawable(Resources.java:854)
at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
at android.graphics.drawable.AnimationDrawable.inflateChildElements(AnimationDrawable.java:327)
at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:297)
at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:130)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1227)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1200)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:715)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
at android.content.res.Resources.loadDrawable(Resources.java:854)
at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
at android.widget.ImageView.<init>(ImageView.java:157)
at android.widget.ImageView.<init>(ImageView.java:145)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:60)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:56)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1026)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1083)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at de.procre.togetheraware.WelcomeActivity.onCreate(WelcomeActivity.java:22)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

最佳答案

在 list 文件的应用程序标记中尝试这些 make android:hardwareAccelerated="false"android:largeHeap="true"像这样

<application
android:largeHeap="true"
android:hardwareAccelerated="false">

关于java - 应用程序停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45755041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com