I used this import android.support.v7.app.Appcompatactivity
for mainactivity.java but I received a red error:
cannot resolve symbol v7
I did invalidate Кэши тоже перезагружаются, но это не сработало. Если я запускаю этот код без этой строки, мое приложение работает на Android 5.1.1, но не работает на Galaxy J6, для чего это строка? src = "https://i.sstatic.net/r0rwt.png"/>
package com.example.bmi;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.support.v7.app.Appcompatactivity
public class MainActivity extends AppCompatActivity {
private EditText height;
private EditText weight;
private TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
height = (EditText) findViewById(R.id.height);
weight = (EditText) findViewById(R.id.weight);
result = (TextView) findViewById(R.id.result);
}
public void calculateBMI(View v) {
String heightStr = height.getText().toString();
String weightStr = weight.getText().toString();
if (heightStr != null && !"".equals(heightStr)
&& weightStr != null && !"".equals(weightStr)) {
float heightValue = Float.parseFloat(heightStr) / 100;
float weightValue = Float.parseFloat(weightStr);
float bmi = weightValue / (heightValue * heightValue);
displayBMI(bmi);
}
}
private void displayBMI(float bmi) {
String bmiLabel = "";
if (Float.compare(bmi, 15f) 0 && Float.compare(bmi, 16f) 0 && Float.compare(bmi, 18.5f) 0 && Float.compare(bmi, 25f) 0 && Float.compare(bmi, 30f) 0 && Float.compare(bmi, 35f) 0 && Float.compare(bmi, 40f)
и мой код build.gradle < /p>
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.bmi"
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.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
//noinspection GradlePath
implementation files('SdkManager\\extras\\android\\support\\v7\\appcompat\\libs and select android-support-v7-appcompat')
}
Подробнее здесь: https://stackoverflow.com/questions/580 ... oid-studio