[英]"package android.support.v7.app does not exist" error in androidStudio
我剛開始使用 androidStudio 進行 android 開發我正在關注 udacity 教程,他們要求我們復制粘貼一些代碼並運行它我無法在粘貼后運行 cod 我認為主要問題是在導入時
import android.support.v7.app.AppCompatActivity;
我已經在互聯網上檢查了這個問題的解決方案,包括 stackoverflow,但似乎對於我嘗試導入的每種情況都不同import androidx.appcompat.app.AppcompatActivity;
而不是import android.support.v7.app.AppCompatActivity;
但它並沒有幫助我使用 androidStudio 3.4 版
主要活動:
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(構建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)
通知缺乏大寫在附錄C ompat進口:
import 'androidx.appcompat.app.AppcompatActivity'
代替附錄C ompatActivity
Java/Android 區分大小寫。 android.support.v7
有點過時了,AndroidX 正在取而代之
自 2019 年 6 月某個地方的 androidx 庫以來,情況發生了變化……要解決這個簡單的問題,請確保執行以下操作;
轉到您的 gradle.properties 文件並啟用 androidx,如步驟 1下方的示例圖片中所示
現在轉到您的 android studio 的頂部菜單,單擊Refactor ,然后單擊“Migrate to androidx”
Android studio 會自動在你的 gradle 中做 androidx 的所有導入語法更正
更新構建 gradle,然后更改導入行
import android.support.v7.app.AppCompatActivity;
到
import androidx.appcompat.app.AppCompatActivity;
並從 AndroidManifest.xml 檢查您的包名稱
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.