実現したいこと
カメラアプリを作成するため、AndroidStudioでレイアウトの画面を表示させる。
発生している問題・分からないこと
カメラアプリを作るために、activity_main.xml に androidx.camera.view.PreviewView を追加すると、レイアウトのデザインビューが表示されなくなりました(スプリットビューにするとコード部分は表示されるがデザイン部分は表示されなくなる)。androidx.camera.view.PreviewViewを削除すると再び表示されます。一方、このアプリを実機で動かすと、実機上には意図した画面が表示されます。
また、以前作った同様のアプリ複数を開いたところ、いずれも、数日前まで表示されていたデザインビューが表示されなくなっていました。そのため、コードの問題ではないだろうとは思いますが、理由も修正法もわからない状態です。
現在、PreviewViewの代わりに同じ位置・大きさのImageViewを作り、レイアウトが出来上がった時点でこれをPreviewViewに置き換えるというようにして作業していますが、煩雑で困っています。
エラーメッセージ
error
1Render Problem 2 3java. lang. NoSuchMethodError: 'void android. hardware. display. DisplayManagerGlobal. 4registerDisplayListener(android. hardware. display. DisplayManager$DisplayListener, android. os. 5Handler, long, java. lang. String)' at android. hardware. display. DisplayManager. 6registerDisplayListener(DisplayManager. java:786) at android. hardware. display. DisplayManager. 7registerDisplayListener(DisplayManager. java:763) at androidx. camera. view. PreviewView. 8startListeningToDisplayChange(PreviewView. java:1102) at androidx. camera. view. PreviewView. 9onAttachedToWindow(PreviewView. java:356) at android. view. View. dispatchAttachedToWindow(View. 10java:22860) at android. view. ViewGroup. dispatchAttachedToWindow(ViewGroup. java:3492) at android. 11view. ViewGroup. dispatchAttachedToWindow(ViewGroup. java:3499) at android. view. ViewGroup. 12dispatchAttachedToWindow(ViewGroup. java:3499) at android. view. ViewGroup. 13dispatchAttachedToWindow(ViewGroup. java:3499) at android. view. ViewGroup. 14dispatchAttachedToWindow(ViewGroup. java:3499) at android. view. AttachInfo_Accessor. 15setAttachInfo(AttachInfo_Accessor. java:69)
該当のソースコード
xml
1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:id="@+id/main" 6 android:layout_width="match_parent" 7 android:layout_height="match_parent" 8 tools:context=".MainActivity"> 9 <TextView 10 android:layout_width="wrap_content" 11 android:layout_height="wrap_content" 12 android:text="Hello World!" 13 app:layout_constraintBottom_toBottomOf="parent" 14 app:layout_constraintEnd_toEndOf="parent" 15 app:layout_constraintStart_toStartOf="parent" 16 app:layout_constraintTop_toTopOf="parent" /> 17 18 <androidx.camera.view.PreviewView 19 android:id="@+id/view_finder" 20 android:layout_width="100dp" 21 android:layout_height="100dp" 22 app:layout_constraintStart_toStartOf="parent" 23 app:layout_constraintTop_toTopOf="parent"/> 24</androidx.constraintlayout.widget.ConstraintLayout>
build.gradle.kts(Module:app)
1・・・ 2dependencies { 3 implementation(libs.androidx.core.ktx) 4 implementation(libs.androidx.appcompat) 5 implementation(libs.material) 6 implementation(libs.androidx.activity) 7 implementation(libs.androidx.constraintlayout) 8 testImplementation(libs.junit) 9 androidTestImplementation(libs.androidx.junit) 10 androidTestImplementation(libs.androidx.espresso.core) 11 12 implementation (libs.androidx.camera.core) 13 implementation (libs.androidx.camera.camera2) 14 implementation (libs.androidx.camera.lifecycle) 15 implementation (libs.androidx.camera.video) 16 implementation (libs.androidx.camera.view ) 17 implementation (libs.androidx.camera.extensions) 18}
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
Render Problem & androidx.camera.view.PreviewView を検索し、出てきたサイトを参考にキャッシュの無効化を行いましたが、変わりはありませんでした。
Clean Projectを行うと、一応デザインビューが表示されますが、レイアウトは完全に崩れていました。その後Rebuild Projectを行うと、再び表示されなくなりました。
その他、AndroidStudioの再起動、PC自体の再起動、AndroidStudioのアンインストールと再インストールを行いましたがこれも変化ありませんでした。
補足
使っているのは AndroidStudio LadyBug Feature Drop(2024.2.2)です。
最初の投稿からだいぶ時間がたちましたが、回答もコメントもいただいていない状態です。理由や修正法がわからなくても良いので、似たような状態が起きた方がおられたらコメントいただけるとありがたいです

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。