iT邦幫忙

0

我的app閃退

  • 分享至 

  • xImage

我現在做的是一個記事本的app,然後像是我要編輯我的記事項目,但如果我想跳回上一個頁面,我按我模擬器的上一頁的建之後我app就會閃退,想請教大大們我是錯在哪裡

我的code:
@Override
protected void onBindViewHolder(@NonNull NoteViewHolder holder, int position, @NonNull Note note) {
holder.titleTextView.setText(note.title);
holder.contentTextView.setText(note.content);
holder.timestampTextView.setText(Utility.timestampTostring(note.timestamp));

        holder.itemView.setOnClickListener((v)->{
        Intent intent = new Intent(context,NoteDetailsActivity.class);
        intent.putExtra("title",note.title);
        intent.putExtra("content",note.content);
        String docId = this.getSnapshots().getSnapshot(position).getId();
        intent.putExtra("docId",docId);
        context.startActivity(intent);


   });


}


錯誤訊息:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.notespro, PID: 9710
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionNoteViewHolder{9b7d091 position=6 id=-1, oldPos=0, pLpos:0 scrap [attachedScrap] tmpDetached no parent} androidx.recyclerview.widget.RecyclerView{dde6614 VFED..... ......I. 0,117-1080,1977 #7f08017d app:id/recyler_view}, adapter:com.example.notespro.NoteAdapter@243bebd, layout:androidx.recyclerview.widget.LinearLayoutManager@e23fcb2, context:com.example.notespro.MainActivity@c88b991
    at androidx.recyclerview.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:6156)
    at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6339)
    at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6300)
    at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6296)
    at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2330)
    at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1631)
    at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1591)
    at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:668)
    at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:4255)
    at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:4010)
    at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4578)
    at android.view.View.layout(View.java:22844)
    at android.view.ViewGroup.layout(ViewGroup.java:6389)
    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1103)
    at android.view.View.layout(View.java:22844)
    at android.view.ViewGroup.layout(ViewGroup.java:6389)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
    at android.view.View.layout(View.java:22844)
    at android.view.ViewGroup.layout(ViewGroup.java:6389)
    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:22844)
    at android.view.ViewGroup.layout(ViewGroup.java:6389)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
    at android.view.View.layout(View.java:22844)
    at android.view.ViewGroup.layout(ViewGroup.java:6389)
    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:22844)
    at android.view.ViewGroup.layout(ViewGroup.java:6389)
    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:784)
    at android.view.View.layout(View.java:22844)
    at android.view.ViewGroup.layout(ViewGroup.java:6389)
    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3470)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2938)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1952)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8171)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
    at android.view.Choreographer.doCallbacks(Choreographer.java:796)
    at android.view.Choreographer.doFrame(Choreographer.java:731)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)

E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

ps抱歉我不知道為什以麼我上傳不了圖片,所以只能先貼文字

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
l101100
iT邦新手 5 級 ‧ 2022-12-26 17:46:22

恩 看起來需要程式高手協助解決

0
willy11837
iT邦見習生 ‧ 2022-12-27 10:56:32

IndexOutOfBoundsException
往這個方向查查

1

String docId = this.getSnapshots().getSnapshot(position).getId();

這行會不會有取到空值得可能?如果會,應該就是他了吧~~

            String docId = null;
            if (docId!=null) {
                docId = this.getSnapshots().getSnapshot(position).getId();
                intent.putExtra("docId", docId);
            }
            context.startActivity(intent);

不好意思請問是這樣改嗎!?

編譯有沒有過不就知道了嗎?

我要發表回答

立即登入回答