4

AndroidX:我正在尝试使用 TextInputLayout,但是当我将其放入我的 XML 中时,我收到此错误:

渲染问题:

Couldn't resolve resource @string/path_password_strike_through

未能启动一门或多门课程

The following classes could not be instantiated:
        com.google.android.material.textfield.TextInputLayout

这里是堆栈跟踪:

java.lang.AssertionError: error in parsing "g/"java.lang.NumberFormatException: For input string: "/"
    at android.util.PathParser_Delegate.getFloats(PathParser_Delegate.java:366)
    at android.util.PathParser_Delegate.createNodesFromPathData(PathParser_Delegate.java:183)
    at android.util.PathParser_Delegate.nCreatePathDataFromString(PathParser_Delegate.java:107)
    at android.util.PathParser.nCreatePathDataFromString(PathParser.java)
    at android.util.PathParser.access$200(PathParser.java:24)
    at android.util.PathParser$PathData.<init>(PathParser.java:76)
    at android.graphics.drawable.VectorDrawable$VFullPath.updateStateFromTypedArray(VectorDrawable.java:2016)
    at android.graphics.drawable.VectorDrawable$VFullPath.inflate(VectorDrawable.java:1967)
    at android.graphics.drawable.VectorDrawable.inflateChildElements(VectorDrawable.java:819)
    at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:717)
    at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
    at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1332)
    at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1291)
    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1266)
    at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:330)
    at android.content.res.Resources_Delegate.getDrawable(Resources_Delegate.java:186)
    at android.content.res.Resources.getDrawable(Resources.java:827)
    at android.graphics.drawable.AnimatedVectorDrawable.inflate(AnimatedVectorDrawable.java:544)
    at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
    at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1332)
    at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1291)
    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1266)
    at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:330)
    at android.content.res.BridgeTypedArray.getDrawable(BridgeTypedArray.java:684)
    at android.graphics.drawable.AnimatedStateListDrawable.parseTransition(AnimatedStateListDrawable.java:473)
    at android.graphics.drawable.AnimatedStateListDrawable.inflateChildElements(AnimatedStateListDrawable.java:455)
    at android.graphics.drawable.AnimatedStateListDrawable.inflate(AnimatedStateListDrawable.java:385)
    at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
    at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1332)
    at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1291)
    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1266)
    at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:330)
    at android.content.res.Resources_Delegate.getDrawable(Resources_Delegate.java:186)
    at android.content.res.Resources.getDrawable(Resources.java:827)
    at android.content.Context.getDrawable(Context.java:626)
    at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:463)
    at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:203)
    at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
    at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:102)
    at androidx.appcompat.widget.TintTypedArray.getDrawable(TintTypedArray.java:76)
    at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:344)
    at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:247)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:401)
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:184)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:142)
    at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:229)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:421)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:432)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:336)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:863)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:327)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:386)
    at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:450)
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:590)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

我正在尝试使用更多的 'android.material.xxx' 而不是 support.design.widget。

我也尝试了 support.design 版本,但它似乎不起作用:/这里可能有什么问题?谢谢指教。

4

1 回答 1

6

遇到了同样的问题。。

将以下代码行添加到您TextInputLayout将解决此问题:

app:passwordToggleDrawable="@string/string_name"

为我工作

于 2018-10-18T19:35:24.030 回答