15

Я пытаюсь использовать предварительный просмотр Android Studio 2.2 1, но если я создам новый проект и добавлю простой EditText и попытаюсь запустить, я получил следующую ошибку.Android Studio 2.2 preview 1 Ошибка EditText

05-20 15:53:00.748 11798-11798/br.com.tutorialandroid.sqlite E/AndroidRuntime: FATAL EXCEPTION: main 
Process: br.com.tutorialandroid.sqlite, PID: 11798 
java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.tutorialandroid.sqlite/br.com.tutorialandroid.sqlite.MainActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class EditText 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2658) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723) 
at android.app.ActivityThread.access$900(ActivityThread.java:172) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:145) 
at android.app.ActivityThread.main(ActivityThread.java:5832) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class EditText 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:770) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:933) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:933) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:511) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:415) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:366) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at br.com.tutorialandroid.sqlite.MainActivity.onCreate(MainActivity.java:22) 
at android.app.Activity.performCreate(Activity.java:6221) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)  
at android.app.ActivityThread.access$900(ActivityThread.java:172)  
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)  
at android.os.Handler.dispatchMessage(Handler.java:102)  
at android.os.Looper.loop(Looper.java:145)  
at android.app.ActivityThread.main(ActivityThread.java:5832)  
at java.lang.reflect.Method.invoke(Native Method)  
at java.lang.reflect.Method.invoke(Method.java:372)  
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)  
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)  
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-v21/abc_edit_text_material.xml from drawable resource ID #0x7f020015 
at android.content.res.Resources.loadDrawableForCookie(Resources.java:3707) 
at android.content.res.Resources.loadDrawable(Resources.java:3575) 
at android.content.res.TypedArray.getDrawable(TypedArray.java:750) 
at android.view.View.<init>(View.java:3939) 
at android.widget.TextView.<init>(TextView.java:923) 
at android.widget.EditText.<init>(EditText.java:74) 
at android.widget.EditText.<init>(EditText.java:70) 
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:60) 
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:56) 
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:112) 
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980) 
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039) 
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)  
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:933)  
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)  
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:933)  
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)  
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)  
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)  
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)  
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)  
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)  
at br.com.tutorialandroid.sqlite.MainActivity.onCreate(MainActivity.java:22)  
at android.app.Activity.performCreate(Activity.java:6221)  
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)  
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611)  
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)  
at android.app.ActivityThread.access$900(ActivityThread.java:172)  
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)  
at android.os.Handler.dispatchMessage(Handler.java:102)  
at android.os.Looper.loop(Looper.java:145)  
at android.app.ActivityThread.main(ActivityThread.java:5832)  
at java.lang.reflect.Method.invoke(Native Method)  
at java.lang.reflect.Method.invoke(Method.java:372)  
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)  
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)  
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #24: <nine-patch> requires a valid 9-patch source image 
at android.graphics.drawable.NinePatchDrawable.updateStateFromTypedArray(NinePatchDrawable.java:445) 
at android.graphics.drawable.NinePatchDrawable.inflate(NinePatchDrawable.java:401) 
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1150) 
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:185) 
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1150) 
at android.graphics.drawable.InsetDrawable.inflate(InsetDrawable.j 

и мой макет

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/content_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="br.com.tutorialandroid.sqlite.MainActivity" 
    tools:showIn="@layout/app_bar_main" 
    tools:layout_editor_absoluteX="0dp" 
    tools:layout_editor_absoluteY="81dp"> 

    <EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:inputType="textPersonName" 
    android:text="Nome" 
    android:ems="10" 
    tools:layout_editor_absoluteX="84dp" 
    tools:layout_editor_absoluteY="262dp" 
    android:id="@+id/txtNome" 
    app:layout_constraintLeft_toLeftOf="@+id/content_main" 
    tools:layout_constraintLeft_creator="0" 
    app:layout_constraintTop_toTopOf="@+id/content_main" 
    tools:layout_constraintTop_creator="0" 
    app:layout_constraintRight_toRightOf="@+id/content_main" 
    tools:layout_constraintRight_creator="0" 
    app:layout_constraintBottom_toBottomOf="@+id/content_main" 
    tools:layout_constraintBottom_creator="0" /> 

</android.support.constraint.ConstraintLayout> 

Мой файл build.gradle (модуль уровня) является

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 
    defaultConfig { 
     applicationId "br.com.tutorialandroid.sqlite" 
     minSdkVersion 15 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:23.4.0' 
    compile 'com.android.support:design:23.4.0' 
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1' 
    testCompile 'junit:junit:4.12' 
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' 
    androidTestCompile 'com.android.support.test:runner:0.5' 
    androidTestCompile 'com.android.support:support-annotations:23.4.0' 
} 

и файл Мой build.gradle (уровень приложений) является

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.0-alpha1' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

И это мой предварительный просмотр макета в AS 2.2 preview 1

enter image description here

+0

вы использовали вектор в вашем проекте? если нет, я думаю, что чистая сборка должна исправить вашу проблему, если да, вы добавили 'vectorDrawables.useSupportLibrary = true' в файл градимента? –

+0

@shayanpourvatan Я ничего не делал, просто добавил EditText в приложение и попытался запустить. И он компилируется без ошибок или предупреждений, но когда вы пытаетесь появиться на устройстве, он закрывается, и я показываю ошибку, о которой я упоминал на эту тему – Gorio

+0

Я борюсь с точно такой же проблемой. И я запускаю Android Studio 2.2 на Linux, как и вы, я думаю. – Rames

ответ

32

После реальной борьбы, это кажется Gradle проблемой. Переход с пониженной скоростью от версии 2.2.0-alpha1 до стабильной версии (2.1 работал для меня).

Меняем build.gradle (уровень приложений) и синхронизации:

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.1.0' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 
+0

Есть ли ошибка на Android трекер? Я хотел бы, чтобы это было решено в следующем выпуске градиента. –

+6

UPDATE: здесь https://code.google.com/p/android/issues/detail?id=210467 –

+2

2.2.0-alpha4 должен отсутствовать через день или два, и, как утверждается, он содержит исправить это. –

1

Это кажется связаны между собой, но у меня была проблема, где edittexts были причиной аварии на Samsung Tab 4, но, казалось, отлично работает на каждом другом устройстве. Наконец, выяснилось, что отсутствует /res/drawable-v21/abc_edit_text_material.xml, поэтому я взял abc_edit_text_material.xml из предыдущего sdk и добавил в свой проект, пока все ошибки не будут разработаны из предстоящих плагинов Gradle.

1

Нет необходимости в Downgradle Просто создайте подкласс, который расширяет EditText. Для примера:

public class Text extends EditText { 
    public Text(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 
} 

Затем использовать этот класс в XML-файле instaed из EditText

<com.example.edittextproblem.Text 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="haha"/> 

и ваша проблема будет решена :)

Смежные вопросы