0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Android - Java】更新型エラーノート

Last updated at Posted at 2025-07-02

ErrorList.png

💥 android.content.ActivityNotFoundException

📄 エラーログ

Logcat
    android.content.ActivityNotFoundException:
    Unable to find explicit activity class
    {sample/sample.ui.sample.sampleActivity};
    have you declared this activity in your AndroidManifest.xml, 
    or does your intent not match its declared <intent-filter>?

🛠 解消手順

AndroidManifest.xmlに以下の記述を追加する

AndroidManifest.xml
    <activity
        android:name=".ui.sample.SampleActivity"
        android:exported="false" />

手動でActivityのクラスファイルを追加時、AndroidManifest.xmlに自動登録されないので注意
AndroidManifestにある場合は、パッケージ名などを確認する。

それ以外にはパッケージ名が間違っている時などにも発生する場合がある。

💥 java.lang.RuntimeException

📄 エラーログ

Logcat
    java.lang.RuntimeException: Unable to start activity
    ComponentInfo{sample/sample.ui.sample.sample.sample.SampleActivity}:
    java.lang.NullPointerException: Attempt to invoke virtual method
    'sample.usecase.UseCases sample.MyApplication.getUseCases()'
    on a null object reference

🛠 解消手順

AndroidManifest.xmlに以下の記述を確認する

AndroidManifest.xml
    <application
        android:name=".MyApplication"

この部分が間違っていると発生する場合がある。

変数定義や呼出元などを確認する

SampleActivity.java
    private MyApplication app;
    
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        app = MyApplication.of(getApplication());
    
        viewModel = ViewModelProviders
            .of(this, new SampleViewModel.Factory(
                    app.getUseCases()
                ))
            .get(SampleViewModel.class);
        // 以下略
    }

今回は MyApplication の変数定義部分を以下の書き方をしていたことが原因で発生していた。

🔎 原因の記述を見る
SampleActivity.java
// ここが原因
private MyApplication app = MyApplication.of(getApplication());

@Override 
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    viewModel = ViewModelProviders
        .of(this, new SampleViewModel.Factory(
                app.getUseCases()
            ))
        .get(SampleViewModel.class);
    // 以下略   
}

今回変数定義の private MyApplication app; の記述と代入部分の app = MyApplication.of(getApplication()); をひとまとめに記述したことで発生していた。

SampleActivity.java
@Override 
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // これはOK(IDEの補完機能による修正)
    MyApplication app = MyApplication.of(getApplication());

    viewModel = ViewModelProviders
        .of(this, new SampleViewModel.Factory(
                app.getUseCases()
            ))
        .get(SampleViewModel.class);
    // 以下略   
}

それ以外にも渡している値の型が違う場合やクラスを呼出す時のクラス名が間違っている場合などに発生する。

💥 It looks like you just edited the targetSdkVersion from 34 to 35 in the editor

📄 エラーログ

Logcat
It looks like you just edited the `targetSdkVersion` from 34 to 35 in the editor.
Be sure to consult the documentation on the behaviors that change as result of this.
The Android SDK Upgrade Assistant can help with safely migrating.

🛠 解消手順

compileSdkのバージョンを上げる

build.gradle(:app)
applay plugin: 'com.android.application'

android {
 compileSdk = 35
 buildToolsVersion "35.0.0"
 
 defaultConfig {
  applicationId "com.sample.sample"
  minSdk = 29 // OS10
  targetSdk = 35 // OS15
 }
}

compileSdk のバージョンを 35 にあげる。

Android Gradle Pluginのバージョンを上げる

build.gradle(SAMPLEAPP-Android)
buildscript {
 repositories{
  // 省略
 }
 dependencies {
  classpath 'com.android.tools.build:gradle:8.6.1'
 }
}

AGP Upgrade Assistant を使用し、Android Gradle Plugin のバージョンを最低でも AGP 8.6.1 にあげる。

🔎 ステーターバーの表示を元に戻す方法

Android15以降を搭載する端末で、targetSdkを35以降にすると Edge To Edge 表示がデフォルトになる。
これによりステータスバーの後ろにアプリの要素が回り込んだ表示となるが、場合によってはステータスバーの表示内容とアプリの要素が重なってしまう。

以下の記述を設定することで Edge To Edge を無効化して従来の表示形式でステータスバーを表示可能になる。

styles.xml
<!-- 以下を記述する -->
<item name="android:windowOptOutEdgeToEdgeEnforcement" tools:targetApi="35">true</item>

💥 Your build is currently configured to use Java XX and Gradle XX

📄 エラーログ

Logcat
Your build is currently configured to use Java 17.0.1 and Gradle 6.7.1

🛠 解消手順

使用中のGradleと対応するJDKをダウンロードする

File -> Project Structure -> Project からプロジェクトで使用中のGradleバージョンを確認する。

ProjectStracture.PNG

Settings -> Build, Execution, Deployment -> Buiild Tools -> Gradle を開き、
Gradle JDK の1つ目の項目を開いてDownload JDK...を開き、対応するJDKバージョンをダウンロードする。

Gradle.PNG

Gradle_2.PNG

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?