[英]"package android.support.v7.app does not exist" error in androidStudio
i am just starting with android development using androidStudio i am following udacity tutorial where they asked us to copy paste some code and run it i am unable to run the cod after pasting i think the major problem is while importing我刚开始使用 androidStudio 进行 android 开发我正在关注 udacity 教程,他们要求我们复制粘贴一些代码并运行它我无法在粘贴后运行 cod 我认为主要问题是在导入时
import android.support.v7.app.AppCompatActivity;
i have checked internet for solution to this problem including stackoverflow but it seems that it is different for each case i have tried to import import androidx.appcompat.app.AppcompatActivity;
我已经在互联网上检查了这个问题的解决方案,包括 stackoverflow,但似乎对于我尝试导入的每种情况都不同
import androidx.appcompat.app.AppcompatActivity;
instead of import android.support.v7.app.AppCompatActivity;
而不是
import android.support.v7.app.AppCompatActivity;
but it didn't hepled i am using androidStudio version 3.4但它并没有帮助我使用 androidStudio 3.4 版
Main activity:主要活动:
package com.example.android.justjava;
/**
* IMPORTANT: Make sure you are using the correct package name.
* This example uses the package name:
* package com.example.android.justjava
* If you get an error when copying this code into Android studio, update it to match teh package name found
* in the project's AndroidManifest.xml file.
**/
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
display(1);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
}
module.App(build gradle): module.App(构建gradle):
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.android.justjava"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
error: cannot find symbol class AppcompatActivity
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 method findViewById(int)
You are using androidx libraries.您正在使用androidx库。
implementation 'androidx.appcompat:appcompat:1.0.2'
Then you can't use the import of support libraries classes.那么就不能使用支持库类的导入了。
It is the right class :这是正确的课程:
import androidx.appcompat.app.AppCompatActivity;
notice lack of uppercase in your App C ompat import:通知缺乏大写在附录C ompat进口:
import 'androidx.appcompat.app.AppcompatActivity'
instead of App C ompatActivity代替附录C ompatActivity
Java/Android is case sensitive. Java/Android 区分大小写。
android.support.v7
is kind of deprecated, AndroidX is replacing it android.support.v7
有点过时了,AndroidX 正在取而代之
Things have changed since androidx library somewhere in june 2019... To solve this simple problem, make sure you do the following;自 2019 年 6 月某个地方的 androidx 库以来,情况发生了变化……要解决这个简单的问题,请确保执行以下操作;
go to your gradle.properties file and enable androidx as you can see in my example picture below step1转到您的 gradle.properties 文件并启用 androidx,如步骤 1下方的示例图片中所示
Now go to the top menu of your android studio, click on Refactor and click on "Migrate to androidx"现在转到您的 android studio 的顶部菜单,单击Refactor ,然后单击“Migrate to androidx”
Android studio automatically will do all the importation syntax corrections of androidx in your gradle Android studio 会自动在你的 gradle 中做 androidx 的所有导入语法更正
update build gradle, then change import line from更新构建 gradle,然后更改导入行
import android.support.v7.app.AppCompatActivity;
to到
import androidx.appcompat.app.AppCompatActivity;
and check your package name from AndroidManifest.xml并从 AndroidManifest.xml 检查您的包名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.