Я новичок в создании приложений для Android, но пока заставка не работает, и, поскольку я не вижу ошибок, приложение просто не запускается в эмуляторе

#java #android #android-studio

#java #Android #android-studio

Вопрос:

Я использую Android Studio, последнюю версию. Я успешно создал простой пользовательский интерфейс cardview и намеревался добавить заставку, однако приложения не будут работать. я тоже поместил код здесь. Пожалуйста, помогите мне.

Это androidmanifest.xml

 <?xml version="1.0" encoding="utf-8"?>
 
 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.DASHBOARD">
    <activity android:name=".Splash">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MainActivity">

    </activity>
</application>
 

это splash java

     package com.example.dashboard;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.airbnb.lottie.LottieAnimationView;

public class Splash extends AppCompatActivity {

    ImageView logo,splashImg;
    TextView appName;
    LottieAnimationView lottieAnimationView;


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

        logo = findViewById(R.id.logo);
        appName = findViewById(R.id.appname);
        splashImg = findViewById(R.id.img);
        lottieAnimationView = findViewById(R.id.lottie);

        splashImg.animate().translationY(-1600).setDuration(1000).setStartDelay(4000);
        logo.animate().translationY(1400).setDuration(1000).setStartDelay(4000);
        appName.animate().translationY(1400).setDuration(1000).setStartDelay(4000);
        lottieAnimationView.animate().translationY(1400).setDuration(1000).setStartDelay(4000);
    }
}

 

это основная деятельность java

     package com.example.dashboard;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.WindowManager;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);


        setContentView(R.layout.activity_main);
    }

}

 

очень ценю ответы, ребята, спасибо

редактировать / здесь трассировка стека

 2021-01-27 16:53:53.118 10697-10697/? I/ample.dashboar: Not late-enabling -Xcheck:jni (already on)
2021-01-27 16:53:53.170 10697-10697/? W/ample.dashboar: Unexpected CPU variant for X86 using defaults: x86
2021-01-27 16:53:53.497 10697-10697/com.example.dashboard W/ample.dashboar: Accessing hidden method Landroid/graphics/drawable/Drawable;->getOpticalInsets()Landroid/graphics/Insets; (light greylist, linking)
2021-01-27 16:53:53.497 10697-10697/com.example.dashboard W/ample.dashboar: Accessing hidden field Landroid/graphics/Insets;->left:I (light greylist, linking)
2021-01-27 16:53:53.497 10697-10697/com.example.dashboard W/ample.dashboar: Accessing hidden field Landroid/graphics/Insets;->right:I (light greylist, linking)
2021-01-27 16:53:53.498 10697-10697/com.example.dashboard W/ample.dashboar: Accessing hidden field Landroid/graphics/Insets;->top:I (light greylist, linking)
2021-01-27 16:53:53.498 10697-10697/com.example.dashboard W/ample.dashboar: Accessing hidden field Landroid/graphics/Insets;->bottom:I (light greylist, linking)
2021-01-27 16:53:53.526 10697-10697/com.example.dashboard W/ample.dashboar: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2021-01-27 16:53:53.526 10697-10697/com.example.dashboard W/ample.dashboar: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2021-01-27 16:53:53.559 10697-10697/com.example.dashboard W/ample.dashboar: Accessing hidden method Landroid/widget/TextView;->getTextDirectionHeuristic()Landroid/text/TextDirectionHeuristic; (light greylist, linking)
2021-01-27 16:53:53.596 10697-10697/com.example.dashboard D/OpenGLRenderer: HWUI GL Pipeline
2021-01-27 16:53:53.646 10697-10724/com.example.dashboard D/HostConnection: HostConnection::get() New Host Connection established 0xe2ea6f90, tid 10724
2021-01-27 16:53:53.664 10697-10724/com.example.dashboard D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2 
2021-01-27 16:53:53.667 10697-10724/com.example.dashboard I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2021-01-27 16:53:53.669 10697-10724/com.example.dashboard I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2021-01-27 16:53:53.669 10697-10724/com.example.dashboard I/OpenGLRenderer: Initialized EGL, version 1.4
2021-01-27 16:53:53.670 10697-10724/com.example.dashboard D/OpenGLRenderer: Swap behavior 1
2021-01-27 16:53:53.670 10697-10724/com.example.dashboard W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2021-01-27 16:53:53.670 10697-10724/com.example.dashboard D/OpenGLRenderer: Swap behavior 0
2021-01-27 16:53:53.692 10697-10724/com.example.dashboard D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
2021-01-27 16:53:53.692 10697-10724/com.example.dashboard D/EGL_emulation: eglCreateContext: 0xe49f7320: maj 2 min 0 rcv 2
2021-01-27 16:53:53.710 10697-10724/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe49f7320: ver 2 0 (tinfo 0xe49f28e0)
2021-01-27 16:53:53.714 10697-10697/com.example.dashboard D/AndroidRuntime: Shutting down VM
2021-01-27 16:53:53.716 10697-10697/com.example.dashboard E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.dashboard, PID: 10697
    java.lang.IllegalStateException: Unable to parse composition
        at com.airbnb.lottie.LottieAnimationView$1.onResult(LottieAnimationView.java:79)
        at com.airbnb.lottie.LottieAnimationView$1.onResult(LottieAnimationView.java:72)
        at com.airbnb.lottie.LottieAnimationView$3.onResult(LottieAnimationView.java:96)
        at com.airbnb.lottie.LottieAnimationView$3.onResult(LottieAnimationView.java:89)
        at com.airbnb.lottie.LottieTask.notifyFailureListeners(LottieTask.java:158)
        at com.airbnb.lottie.LottieTask.access$200(LottieTask.java:27)
        at com.airbnb.lottie.LottieTask$1.run(LottieTask.java:133)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: com.airbnb.lottie.parser.moshi.JsonDataException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $
        at com.airbnb.lottie.parser.moshi.JsonUtf8Reader.beginObject(JsonUtf8Reader.java:144)
        at com.airbnb.lottie.parser.LottieCompositionMoshiParser.parse(LottieCompositionMoshiParser.java:57)
        at com.airbnb.lottie.LottieCompositionFactory.fromJsonReaderSyncInternal(LottieCompositionFactory.java:389)
        at com.airbnb.lottie.LottieCompositionFactory.fromJsonReaderSync(LottieCompositionFactory.java:382)
        at com.airbnb.lottie.LottieCompositionFactory.fromJsonInputStreamSync(LottieCompositionFactory.java:312)
        at com.airbnb.lottie.LottieCompositionFactory.fromJsonInputStreamSync(LottieCompositionFactory.java:305)
        at com.airbnb.lottie.LottieCompositionFactory.fromRawResSync(LottieCompositionFactory.java:268)
        at com.airbnb.lottie.LottieCompositionFactory$3.call(LottieCompositionFactory.java:233)
        at com.airbnb.lottie.LottieCompositionFactory$3.call(LottieCompositionFactory.java:228)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
2021-01-27 16:53:53.729 10697-10724/com.example.dashboard D/HostConnection: createUnique: call
2021-01-27 16:53:53.729 10697-10724/com.example.dashboard D/HostConnection: HostConnection::get() New Host Connection established 0xe2ea8c50, tid 10724
2021-01-27 16:53:53.733 10697-10724/com.example.dashboard D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2 
2021-01-27 16:53:53.733 10697-10724/com.example.dashboard E/eglCodecCommon: GoldfishAddressSpaceHostMemoryAllocator: ioctl_ping failed for device_type=5, ret=-1
 

здесь activity_splash

 <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".Splash">

    <ImageView
        android:id="@ id/img"
        android:layout_width="match_parent"
        android:layout_height="900dp"
        android:scaleType="centerCrop"
        android:src="@color/white"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0" />

    <ImageView
        android:id="@ id/logo"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/viadeo"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias=".1" />

    <TextView
        android:id="@ id/appname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Splash"
        android:textSize="50dp"
        android:fontFamily="cursive"
        android:textColor="@color/black"
        app:layout_constraintVertical_bias="0"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/logo"/>

       <com.airbnb.lottie.LottieAnimationView
           android:id="@ id/lottie"
           android:layout_width="wrap_content"
           android:layout_height="200dp"
           app:layout_constraintVertical_bias="0"
           app:lottie_rawRes="@raw/horse1611730774"
           app:lottie_autoPlay="true"
           app:layout_constraintBottom_toBottomOf="parent"
           app:layout_constraintEnd_toEndOf="parent"
           app:layout_constraintStart_toStartOf="parent"
           app:layout_constraintTop_toBottomOf="@id/appname"/>


</androidx.constraintlayout.widget.ConstraintLayout>
 

Комментарии:

1. пожалуйста, опубликуйте трассировку стека

2. просто добавил его, может взглянуть, спасибо

3. Похоже, ваш lottie файл поврежден

4. Я хочу увидеть ваш XML-файл splash activity

5. я просто обновляю его в сообщении

Ответ №1:

Возможно, что-то не так с вашим файлом lottie, говорит ваш stacktrace:

Caused by: com.airbnb.lottie.parser.moshi.JsonDataException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $

Так что, возможно, исходный ресурс, который вы используете с lottie, просто несовместим или что-то пошло не так с ним, возможно, попробуйте другой ресурс

Комментарии:

1. Спасибо. теперь оно работает. однако, можете ли вы мне помочь, анимация идет хорошо, однако экран-заставка просто опускается, а не переключается на экран основного действия.

2. не беспокойтесь, ваш вопрос был лучше, чем у большинства людей, которые публикуют здесь в первый раз, просто не забывайте всегда публиковать трассировку стека, если что-то сбой, кроме того, что ваш вопрос был в порядке, добро пожаловать в stack overflow 🙂