java .lang.ClassCastException: androidx.constraintlayout.widget.ConstraintLayout нельзя привести к android .widget.LinearLayout - PullRequest
0 голосов
/ 02 мая 2020

Снимок экрана LOGCAT

При загрузке данных в приложение recyclerview происходит сбой. Я использую метод перезагрузки для загрузки данных, которые используют аннотации ROOM libtrary.

@Dao
public interface NoteDao {
    @Query("INSERT INTO notes (contents) VALUES ('New note')")
    void create();

    @Query("SELECT * FROM notes")
    List<Note> getAllNotes();

    @Query("UPDATE notes SET contents = :contents WHERE id = :id")
    void save(String contents, int id);
}

И класс базы данных, чтобы, наконец, использовать эти методы: -

    @Database(entities = {Note.class}, version = 1)
public abstract class NoteDatabase extends RoomDatabase {
    public abstract NoteDao noteDao();
}

Я использовал базу данных для хранения мои данные на телефоне и отображать их в виде переработчика с помощью библиотеки ROOM и просмотра переработчика.

edit:

    2020-05-02 22:23:31.647 7612-7612/? I/m.example.note: Not late-enabling -Xcheck:jni (already on)
        2020-05-02 22:23:31.805 7612-7612/? E/m.example.note: Unknown bits set in runtime_flags: 0x8000
        2020-05-02 22:23:31.809 7612-7612/? W/m.example.note: Unexpected CPU variant for X86 using defaults: x86
        2020-05-02 22:23:32.307 7612-7649/com.example.notes D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
        2020-05-02 22:23:32.308 7612-7649/com.example.notes W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
        2020-05-02 22:23:32.300 7612-7612/com.example.notes W/RenderThread: type=1400 audit(0.0:31): avc: denied { write } for name="property_service" dev="tmpfs" ino=7421 scontext=u:r:untrusted_app:s0:c146,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0
        2020-05-02 22:23:32.361 7612-7649/com.example.notes D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
        2020-05-02 22:23:32.366 7612-7649/com.example.notes D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
        2020-05-02 22:23:32.371 7612-7649/com.example.notes D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
        2020-05-02 22:23:32.634 7612-7612/com.example.notes W/m.example.note: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
        2020-05-02 22:23:32.634 7612-7612/com.example.notes W/m.example.note: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
        2020-05-02 22:23:32.954 7612-7647/com.example.notes D/HostConnection: HostConnection::get() New Host Connection established 0xdfb13b90, tid 7647
        2020-05-02 22:23:32.956 7612-7647/com.example.notes D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements 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_gles_max_version_2
        2020-05-02 22:23:32.963 7612-7647/com.example.notes W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
        2020-05-02 22:23:32.974 7612-7647/com.example.notes D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
        2020-05-02 22:23:32.974 7612-7647/com.example.notes D/EGL_emulation: eglCreateContext: 0xdfb19fe0: maj 2 min 0 rcv 2
        2020-05-02 22:23:32.982 7612-7647/com.example.notes D/EGL_emulation: eglMakeCurrent: 0xdfb19fe0: ver 2 0 (tinfo 0xeafdd720)
        2020-05-02 22:23:33.008 7612-7647/com.example.notes W/Gralloc3: mapper 3.x is not supported
        2020-05-02 22:23:33.009 7612-7647/com.example.notes D/HostConnection: createUnique: call
        2020-05-02 22:23:33.009 7612-7647/com.example.notes D/HostConnection: HostConnection::get() New Host Connection established 0xdfb159e0, tid 7647
        2020-05-02 22:23:33.010 7612-7647/com.example.notes D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements 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_gles_max_version_2
        2020-05-02 22:23:33.011 7612-7647/com.example.notes D/eglCodecCommon: allocate: Ask for block of size 0x1000
        2020-05-02 22:23:33.011 7612-7647/com.example.notes D/eglCodecCommon: allocate: ioctl allocate returned offset 0x3ff708000 size 0x2000
        2020-05-02 22:23:33.134 7612-7647/com.example.notes D/EGL_emulation: eglMakeCurrent: 0xdfb19fe0: ver 2 0 (tinfo 0xeafdd720)
        2020-05-02 22:23:33.412 7612-7647/com.example.notes D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
        2020-05-02 22:23:33.968 7612-7647/com.example.notes I/OpenGLRenderer: Davey! duration=940ms; Flags=1, IntendedVsync=1678045930964, Vsync=1678045930964, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=1678049722700, AnimationStart=1678049778500, PerformTraversalsStart=1678049824200, DrawStart=1678148190700, SyncQueued=1678153229700, SyncStart=1678265306200, IssueDrawCommandsStart=1678265434300, SwapBuffers=1678907520400, FrameCompleted=1679098560600, DequeueBufferDuration=130000, QueueBufferDuration=256000,
        2020-05-02 22:23:34.017 7612-7612/com.example.notes I/Choreographer: Skipped 64 frames!  The application may be doing too much work on its main thread.
        2020-05-02 22:23:34.034 7612-7647/com.example.notes I/OpenGLRenderer: Davey! duration=1098ms; Flags=0, IntendedVsync=1678065846104, Vsync=1679132512728, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=1679148005600, AnimationStart=1679148075500, PerformTraversalsStart=1679150383500, DrawStart=1679155413600, SyncQueued=1679156122800, SyncStart=1679156344300, IssueDrawCommandsStart=1679156409800, SwapBuffers=1679157415000, FrameCompleted=1679164765900, DequeueBufferDuration=93000, QueueBufferDuration=1644000,
        2020-05-02 22:23:38.514 7612-7612/com.example.notes D/AndroidRuntime: Shutting down VM
        2020-05-02 22:23:38.522 7612-7612/com.example.notes E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.example.notes, PID: 7612
        java.lang.ClassCastException: androidx.constraintlayout.widget.ConstraintLayout cannot be cast to android.widget.LinearLayout
        at com.example.notes.NotesAdapter$NoteViewHolder.<init>(NotesAdapter.java:24)
        at com.example.notes.NotesAdapter.onCreateViewHolder(NotesAdapter.java:37)
        at com.example.notes.NotesAdapter.onCreateViewHolder(NotesAdapter.java:15)
        at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6794)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5975)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4194)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1183)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:870)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:889)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:446)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at com.android.internal.policy.DecorView.onLayout(DecorView.java:779)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3080)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2590)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1721)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7598)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
        at android.view.Choreographer.doCallbacks(Choreographer.java:790)
        at android.view.Choreographer.doFrame(Choreographer.java:725)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        2020-05-02 22:23:38.523 7612-7612/com.example.notes E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
        2020-05-02 22:23:38.539 7612-7612/com.example.notes I/Process: Sending signal. PID: 7612 SIG: 9

1 Ответ

1 голос
/ 02 мая 2020

Ваша проблема лежит здесь java.lang.ClassCastException: androidx.constraintlayout.widget.ConstraintLayout cannot be cast to android.widget.LinearLayout

Возможно, вы могли бы объявить constraintlayout представление как LinearLayout.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...