问题
Hi friends can anyone please help me in this. i want to create a login page in this way
But it is not working in emulator and android 8 phone. it is working in android 5 phone. Working fine if i remove the image view which contains curve. getting this error when i try in android 8 or emulator.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.loginapi/com.example.loginapi.views.Loginactivity}: android.view.InflateException: Binary XML file line #11 in com.example.loginapi:layout/activity_main: Binary XML file line #11 in com.example.loginapi:layout/activity_main: Error inflating class ImageView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) Caused by: android.view.InflateException: Binary XML file line #11 in com.example.loginapi:layout/activity_main: Binary XML file line #11 in com.example.loginapi:layout/activity_main: Error inflating class ImageView Caused by: android.view.InflateException: Binary XML file line #11 in com.example.loginapi:layout/activity_main: Error inflating class ImageView Caused by: android.content.res.Resources$NotFoundException: Drawable com.example.loginapi:drawable/wave with resource ID #0x7f07007b Caused by: android.content.res.Resources$NotFoundException: File res/drawable/wave.xml from drawable resource ID #0x7f07007b at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:876) at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:659) at android.content.res.Resources.getDrawableForDensity(Resources.java:906) at android.content.res.Resources.getDrawable(Resources.java:845) at android.content.Context.getDrawable(Context.java:687) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:463) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:203) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191) at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:102) at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:59) at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:78) at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68) at android.support.v7.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:182) at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106) at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266) at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316) at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1061) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084) at android.view.LayoutInflater.inflate(LayoutInflater.java:682) at android.view.LayoutInflater.inflate(LayoutInflater.java:534) at android.view.LayoutInflater.inflate(LayoutInflater.java:481) at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) com.example.loginapi.views.Loginactivity.onCreate(Loginactivity.java:59) at android.app.Activity.performCreate(Activity.java:7802) at android.app.Activity.performCreate(Activity.java:7791) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) Caused by: java.lang.IllegalArgumentException: Path string cannot be empty. at android.util.PathParser.nCreatePathDataFromString(Native Method) at android.util.PathParser.access$200(PathParser.java:25) at android.util.PathParser$PathData.<init>(PathParser.java:78) at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:2039) at android.graphics.drawable.VectorDrawable$VFullPath.inflate(VectorDrawable.java:1990) at android.graphics.drawable.VectorDrawable.inflateChildElements(VectorDrawable.java:836) at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:734) at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:144) at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1402) at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1361) at android.content.res.ResourcesImpl.loadXmlDrawable(ResourcesImpl.java:939) at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:862) ... 41 more
My code wave.xml
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="600dp"
android:height="600dp"
android:viewportWidth="600"
android:viewportHeight="600">
<path
android:fillColor="#11b6ed"
android:fillAlpha="0"
android:strokeColor="#11b6ed"
android:strokeWidth="1"
android:pathData="" />
<path
android:fillColor="#11b6ed"
android:fillAlpha="0"
android:strokeColor="#11b6ed"
android:strokeWidth="1"
android:pathData="" />
<path
android:fillColor="#11b6ed"
android:strokeWidth="1"
android:pathData="M0 00L637.5 00L637.5 519.0C528.33 483.94 424.58 482.69 326.25 516.02C227.91 549.35 119.17 545.6 0 504.77L0 00Z" />
<path
android:fillColor="#11b6ed"
android:fillAlpha="0"
android:strokeColor="#11b6ed"
android:strokeWidth="1"
android:pathData="M0 00L637.5 00L637.5 519.0C528.33 483.94 424.58 482.69 326.25 516.02C227.91 549.35 119.17 545.6 0 504.77L0 00Z" />
<path
android:fillColor="#11b6ed"
android:fillAlpha="0"
android:strokeColor="#11b6ed"
android:strokeWidth="1"
android:pathData="M0 00L637.5 00L637.5 519.0C528.33 483.94 424.58 482.69 326.25 516.02C227.91 549.35 119.17 545.6 0 504.77L0 00Z" />
</vector
activity_login.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".views.Loginactivity"
>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="364dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/wave" />
<Button
android:id="@+id/imageButton2"
android:layout_width="148dp"
android:layout_height="48dp"
android:background="@null"
android:drawableLeft="@drawable/google"
android:text="Sign In With \n Google"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.241"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.535" />
<Button
android:id="@+id/imageButton"
android:layout_width="148dp"
android:layout_height="48dp"
android:background="@null"
android:drawableLeft="@drawable/facebook"
android:text="Sign In With \n Facebook"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.821"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.535" />
<EditText
android:id="@+id/username"
android:layout_width="250dp"
android:layout_height="48dp"
android:autofillHints=""
android:hint="@string/username"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.286"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.748" />
<EditText
android:id="@+id/password"
android:layout_width="250dp"
android:layout_height="57dp"
android:hint="@string/tvpassword"
android:inputType="textPassword"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.286"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.847" />
<Button
android:id="@+id/btn_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_login"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.51"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.954" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OR"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.631" />
<View
android:id="@+id/View03"
android:layout_width="140dp"
android:layout_height="3dp"
android:background="#acafb0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.921"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.629" />
<View
android:layout_width="140dp"
android:layout_height="3dp"
android:background="#acafb0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.148"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.626" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign in to Explico"
android:textColor="#ed0741"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.53"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.457" />
</android.support.constraint.ConstraintLayout>
this is the expected output:
回答1:
If srcCompat
you should use android.support.v7.widget.AppCompatImageView
instead of ImageView
.
<android.support.v7.widget.AppCompatImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="364dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/wave" />
And add this in build.gradle
android {
defaultConfig {
vectorDrawables {
useSupportLibrary = true
}
}
}
OR use src
instead of srcCompat
in ImageView
.
I hope this will help .
回答2:
Here is problem in your image in first 2 path tags android:pathData=""
is empty.
Because of empty pathData app is crashed and you getting error.
Please use another image or below vector code:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="600dp"
android:height="600dp"
android:viewportWidth="600"
android:viewportHeight="600">
<path
android:fillColor="#11b6ed"
android:strokeWidth="1"
android:pathData="M0 00L637.5 00L637.5 519.0C528.33 483.94 424.58 482.69 326.25 516.02C227.91 549.35 119.17 545.6 0 504.77L0 00Z" />
<path
android:fillColor="#11b6ed"
android:fillAlpha="0"
android:strokeColor="#11b6ed"
android:strokeWidth="1"
android:pathData="M0 00L637.5 00L637.5 519.0C528.33 483.94 424.58 482.69 326.25 516.02C227.91 549.35 119.17 545.6 0 504.77L0 00Z" />
<path
android:fillColor="#11b6ed"
android:fillAlpha="0"
android:strokeColor="#11b6ed"
android:strokeWidth="1"
android:pathData="M0 00L637.5 00L637.5 519.0C528.33 483.94 424.58 482.69 326.25 516.02C227.91 549.35 119.17 545.6 0 504.77L0 00Z" />
</vector>
And use android:src="@drawable/wave"
instead of app:srcCompat="@drawable/wave"
I hope its work for you.
来源:https://stackoverflow.com/questions/59860670/wave-curve-in-android-studio