ошибка: невозможно получить доступ к DrawerLayout при использовании AppCompatActivity - PullRequest
0 голосов
/ 15 октября 2019

Использование appcompat "com.android.support:appcompat-v7:28.0.0"

Я не использую android.support.v4.widget.DrawerLayout в своей деятельности. Даже при получении следующей ошибки при запуске приложения на тестовом устройстве

error: cannot access DrawerLayout
public class MainActivity extends AppCompatActivity {
   ^
  class file for android.support.v4.widget.DrawerLayout not found

app.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
    applicationId "com.xx.xx"
    minSdkVersion 21
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

compileOptions {
    sourceCompatibility 1.8
    targetCompatibility 1.8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'org.apache.commons:commons-lang3:3.7'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Activity

package com.xx.xx;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.AppCompatEditText;
import android.support.v7.widget.AppCompatTextView;
import android.widget.LinearLayout;
import android.widget.ToggleButton;

public class MainActivity extends AppCompatActivity {

private LinearLayout stateContainer;
private ToggleButton toggleNw;
private ToggleButton toggleLocation;
private AppCompatEditText etLanguageCode;
private AppCompatEditText etCountryCode;
private AppCompatTextView txSplittedText;
private ToggleButton toggleState;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    stateContainer = findViewById(R.id.stateContainer);
    toggleNw = findViewById(R.id.toggleNw);
    toggleLocation = findViewById(R.id.toggleLocation);
    etLanguageCode = findViewById(R.id.etLanguageCode);
    etCountryCode = findViewById(R.id.etCountryCode);
    txSplittedText = findViewById(R.id.txSplittedText);
    toggleState = (ToggleButton) findViewById(R.id.toggleState);
}
}

1 Ответ

0 голосов
/ 15 октября 2019

файл класса для android.support.v4.widget.DrawerLayout не найден

DrawerLayout не включен в библиотеку поддержки дизайна. Он находится внутри библиотек android.support.v4.

Вы можете добавить зависимость com.android.support:drawerlayout:28.0.0.

...