インターフェースメソッド 'java.lang.Object[] java.util.Collection.toArray()' を null obj で呼び出そうとした場合。
2022-02-24 21:42:42
遭遇しました。ある理由により、NULLオブジェクト参照でインターフェースメソッド 'java.lang.Object[] java.util.Collection.toArray()' を呼び出そうとしました。
デタラメは言わない、ただ文句を言う
今日、上記のエラーに遭遇し、その原因を発見するのに大変な労力を要しました。
私のシナリオはこんな感じです。
// Step 1, there is no data inside the liveBeanList at this point
private List<LiveDetailBean.LiveBean> liveBeanList=new ArrayList<>();
//use liveBeanList to set the adapter for the recyclerView
recyclerView.setAdapter(liveBeanList);
//request network data, get a List netList, then
liveBeanList.addAll(netList);
// then the above error appears, after looking, it turns out that because the netList loaded from the network is empty, so the above error appears. (In addition, if you then adapter.notifyDataSetChanged(), there will be a similar error)
要約すると、ネットワークListのデータを読み込む際、ローカルListにデータを追加する際、まずネットワークデータが空かどうかを判断し、空でなければローカルListに追加する必要があります。
関連
-
Android 開発において、null オブジェクトの参照で仮想メソッドを呼び出そうとする。
-
Android フロントカメラのビデオ録画に失敗しました (MediaRecorder: start failed: -19)
-
エラーの報告です。ArrayAdapter は、リソース ID が TextView である必要があります。
-
パッケージが見つからないエラー 解決策と jdk の切り替え
-
Android LayoutInflaterの原則の分析は、ビュー(a)のステップの深い理解によってあなたのステップを取る
-
ライブ画面録画のAndroid実装 (a) ScreenRecorderの簡易解析
-
Manifest merger failed : Android 12以降をターゲットとするアプリは、明示的な指定が必要です。
-
アンドロイドプログレスバー自定义
-
android start activity report android.content.res.Resources$NotFoundException: 文字列リソースID #0x0
-
ARMアセンブリ共通命令 NULL演算 NOP命令
最新
-
nginxです。[emerg] 0.0.0.0:80 への bind() に失敗しました (98: アドレスは既に使用中です)
-
htmlページでギリシャ文字を使うには
-
ピュアhtml+cssでの要素読み込み効果
-
純粋なhtml + cssで五輪を実現するサンプルコード
-
ナビゲーションバー・ドロップダウンメニューのHTML+CSSサンプルコード
-
タイピング効果を実現するピュアhtml+css
-
htmlの選択ボックスのプレースホルダー作成に関する質問
-
html css3 伸縮しない 画像表示効果
-
トップナビゲーションバーメニュー作成用HTML+CSS
-
html+css 実装 サイバーパンク風ボタン
おすすめ
-
Androidでコンストラクタのインテントを解決できない原因と解決策
-
警告: 構成 'compile' は廃止され、'implementation' と 'api' に置き換わりました。
-
ADBサーバーがACKしない問題を解決しました。
-
障害発生 [INSTALL_FAILED_OLDER_SDK] 解決方法
-
エラーを解決する SSLピアが正しくシャットダウンされない
-
root化されているのですが、adb shellの後、suを入力するとpermission deniedと表示されます。
-
android.content.res.Resources$NotFoundException: 文字列リソースID #0x1エラー
-
アンドロイドについて:DescendantFocusability いくつかの使用感
-
android.view.inflateexception バイナリ xml ファイル行例外の解決方法
-
java.util.Iterator java.util.List.iterator()' で null オブジェクト参照例外が発生した場合の解決策を紹介します。