Cannot resolve symbol 'AppCompatActivity'

IDEAndroid Studio

問題発生

 状態:解決済  閲覧数:4,602  投稿日:2018-05-19  更新日:2018-05-19

ビルド成功するが、ソースコードが赤く表示されている



発生箇所


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {{

メッセージ


Cannot resolve symbol 'AppCompatActivity'


解決できない

 閲覧数:576 投稿日:2018-05-19 更新日:2018-05-19

未解決


色々試したが、全て失敗
・時間の無駄だった

▼app/build.gradle
apply plugin: 'com.android.application'

android {
   compileSdkVersion 23
   buildToolsVersion '27.0.3'

   defaultConfig {
       applicationId "com.example.kanehiro.twotouchmail"
       minSdkVersion 16
       targetSdkVersion 23
       versionCode 1
       versionName "1.0"
   }
   buildTypes {
       release {
           minifyEnabled false
           proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
       }
   }
}

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   testCompile 'junit:junit:4.12'
   compile 'com.android.support:appcompat-v7:23.+'
   //compile 'com.android.support:appcompat-v7:XX.X.+'
   //classpath 'com.android.tools.build:gradle:2.3.1'
   //compile 'com.android.support:appcompat-v7:+'
}


解決した

 閲覧数:723 投稿日:2018-05-19 更新日:2018-06-11

案1.minSdkVersion


「minSdkVersion」を「compileSdkVersion」へ変更したら解決した
・16 → 23

▼app/build.gradle
apply plugin: 'com.android.application'

android {
   compileSdkVersion 23
   buildToolsVersion '27.0.3'

   defaultConfig {
       applicationId "com.example.kanehiro.twotouchmail"
       //minSdkVersion 16
       minSdkVersion 23
       targetSdkVersion 23
       versionCode 1
       versionName "1.0"
   }
   buildTypes {
       release {
           minifyEnabled false
           proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
       }
   }
}

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   testCompile 'junit:junit:4.12'
   compile 'com.android.support:appcompat-v7:23.+'
}


案2.「.idea」フォルダを削除


1.「.idea」フォルダ場所を確認
・画面左側のプロジェクト部分を右クリック
・「Show in Explorer」を選択
L:\Android\copysamplecode\makeitunderstand\Ch03\AnbayasiRoulette\.idea

2.プロジェクトClose
・今開いているAndroid Studio プロジェクトを閉じる

3.「.idea」フォルダ削除

4.プロジェクトを開く
・「please select Android SDK」エラーが発生
・解決すると、「Cannot resolve symbol 'AppCompatActivity'」が表示されなくなる


気が付いたこと

 閲覧数:521 投稿日:2018-06-11 更新日:2018-06-11

気が付いたこと


案1.で試したminSdkVersionは必ずしも関係ないみたい
・但し、うまくいくこともある
・理由は不明

案2処理結果例
▼app/build.gradle
apply plugin: 'com.android.application'

android {
   compileSdkVersion 23
   buildToolsVersion '27.0.3'

   defaultConfig {
       applicationId "com.example.kanehiro.anbayasiroulette"
       minSdkVersion 16
       targetSdkVersion 23
       versionCode 1
       versionName "1.0"
   }
   buildTypes {
       release {
           minifyEnabled false
           proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
       }
   }
}

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   testCompile 'junit:junit:4.12'
   compile 'com.android.support:appcompat-v7:23.+'
   compile 'com.android.support:recyclerview-v7:23.+'
   compile 'com.android.support:cardview-v7:23.+'
}


未確認


「.idea」フォルダではなく「libraries」フォルダ?
・改めて下記リンク先を確認してみたら、「.idea」フォルダではなく「libraries」フォルダだけで良いみたい
Cannot resolve symbol 'AppCompatActivity'


Android Studio で、エラーメッセージをコピー

「Vector Asset 」が開けない。[File] → [New] したのに [Vector Asset]が表示されない



週間人気ページランキング / 3-3 → 3-9
順位 ページタイトル抜粋 アクセス数
1 Android FAQ 13
2 ★★ を型に解決できません | エラー(エラー) 4
3 Unexpected error while launching logcat | エラー(エラー) 3
3 R.java was modified manually! Reverting to generated version! | エラー(エラー) 3
4 [エラー] W/ResourceType(308): Failure getting entry for 0x7f030001 (t=2 e=1) in package 0: 0xffffffb5 | エラー(エラー) 2
4 Sorry! The application ★★ has stopped unexpectedly.Please try again. | エラー(エラー) 2
4 エラー対応 2
4 型 ○○親クラス名.△△ネストクラス名 は継承された抽象メソッド AsyncTask<第1引数,第2引数,第3引数>.doInBackground(Object...) を実装する必要があります | エラー(エラー) 2
5 Project build error: Non-resolvable parent POM: Failure to find | エラー 1
5 adb shell … error: device not found | Android Debug Bridge (adb) 1
5 インポートされた ★★ は見つかりません | エラー 1
5 ログイン 1
5 アプリをビルドして実行する | アプリ化(環境構築) 1
5 Project has no project.properties file! Edit the project properties to set one. | エラー(エラー) 1
5 Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties | エラー(エラー) 1
5 E/AudioPlayer(★★): FAILED renaming /mnt/sdcard/tmprecording.3gp to /android_asset/●●.mp3 | エラー 1
5 E/Trace(★★): error opening trace file: No such file or directory | エラー(エラー) 1
5 emulator-5554 disconnected! Cancelling | エラー(エラー) 1
5 この行に複数マーカーがあります | エラー(エラー) 1
5 The process android.process.acore has stopped unexpectedly. Please try again. | エラー(エラー) 1
2026/3/10 5:05 更新