Error handling AppcompatActivity出现问题-错误:找不到符号类AppcompatActivity
我正在使用udacity学习android开发,我遇到了一个问题。出现了一些错误:Error handling AppcompatActivity出现问题-错误:找不到符号类AppcompatActivity,error-handling,appcompatactivity,android-appcompat,Error Handling,Appcompatactivity,Android Appcompat,我正在使用udacity学习android开发,我遇到了一个问题。出现了一些错误: error: package android.v7.app does not exist error: cannot find symbol class AppCompatActivity error: method does not override or implement a method from a supertype error: cannot find symbol variabl
error: package android.v7.app does not exist
error: cannot find symbol class AppCompatActivity
error: method does not override or implement a method from a supertype
error: cannot find symbol variable super
error: cannot find symbol method setContentView(int)
error: cannot find symbol class openNumbersList
error: cannot find symbol method startActivity(Intent)
一切都很好,但我遵循一个教程,注意到我在主要活动中导入的内容与教程中的内容不匹配,因此我更改了:
import...
到
甚至在此之前,AppCompatActivity
也是红色的:
主要活动:
package com.example.android.miwok;
import android.content.Intent;
import android.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the content of the activity to use the activity_main.xml layout file
setContentView(R.layout.activity_main);
}
public void openNumbersList(View view){
Intent i = new Intent(this, openNumbersList.class);
startActivity(i);
}
}
格拉德尔:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.example.android.miwok"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:23.3.0'
implementation 'com.android.support:support-v4:23.3.0'
implementation 'com.android.support:design:23.3.0'
}
希望这有帮助。我假设您忘记将依赖项添加到appcompat支持库中。将此添加到应用程序文件夹中的
build.gradle
:
dependencies {
...
// Add this line
implementation 'artifact com.android.support:appcompat-v7:28.0.0-alpha1'
}
然而,您也应该阅读其他教程,因为当您不知道依赖关系在Android中如何工作时,您将不可避免地面临更多问题。如果你在Android Studio中创建一个新项目,它将为你创建一个可运行的应用程序,这是一个很好的起点
编辑
我重新读取了您的代码,导入不正确。一定是
android.support.v7.app.AppCompatActivity
而不是
android.v7.app.AppCompatActivity
固定格式是的,我一定要做一些关于依赖关系如何工作的研究。我将build.gradle文件添加为添加:implementation'artifact com.android.support:appcompat-v7:23.0.0-alpha1'似乎不起作用。我从Github下载了这个项目,因为我正在使用android studio来了解他们不久前可能在不同版本的android studio上创建的项目,这可能会很有用。谢谢你能给我更多的帮助@德尼斯洛
android.v7.app.AppCompatActivity