I'm trying to use Android Studio 2.2 preview 1, but if i create a new project and add a simple EditText and try to run, i got the following error.
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
and my layout is
<?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>
My build.gradle (module level) file is
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'
}
and My build.gradle (app level) file is
// 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
}
And this is my layout preview in AS 2.2 preview 1
After a real struggle, this seems to be a gradle problem. Downgradle gradle from 2.2.0-alpha1 to stable version (2.1 worked for me).
So change build.gradle (app level) and sync:
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
}
This seems related, but I had an issue where the edittexts were causing a crash on the Samsung Tab 4, but seemed to work fine on every other device. Finally discovered that the /res/drawable-v21/abc_edit_text_material.xml was missing, so I took abc_edit_text_material.xml from the previous sdk and added to my project until all the bugs are worked out from the upcoming Gradle plugins.
No need for Downgradle Just create a sub class that extends EditText. For Example:
public class Text extends EditText {
public Text(Context context, AttributeSet attrs) {
super(context, attrs);
}
}
Then use this class in xml file instaed of EditText
<com.example.edittextproblem.Text
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="haha"/>
and your problem will be solved :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With