0

插入引导下拉菜单时应用程序停止。使用了代码部分中可用的位。按钮标签等正在工作,但插入下拉应用程序时停止

原木猫

11-21 11:28:30.219 10128-10128/com.example.usr1.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.usr1.myapplication, PID: 10128
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.usr1.myapplication/com.example.usr1.myapplication.feature.MainActivity}: android.view.InflateException: Binary XML file line #0: 
Binary XML file line #0: Error inflating class com.beardedhen.androidbootstrap.BootstrapDropDown
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class  com.beardedhen.androidbootstrap.BootstrapDropDown
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class com.beardedhen.androidbootstrap.BootstrapDropDown
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
    at android.view.LayoutInflater.createView(LayoutInflater.java:647)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:286)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at  com.example.usr1.myapplication.feature.MainActivity.onCreate(MainActivity.java:30)
    at android.app.Activity.performCreate(Activity.java:6975)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalArgumentException: text cannot be null
    at android.graphics.Paint.measureText(Paint.java:1856)
    at com.beardedhen.androidbootstrap.BootstrapDropDown.measureStringWidth(BootstrapDropDown.java:294)
    at com.beardedhen.androidbootstrap.BootstrapDropDown.createDropDown(BootstrapDropDown.java:158)
    at com.beardedhen.androidbootstrap.BootstrapDropDown.initialise(BootstrapDropDown.java:140)
    at com.beardedhen.androidbootstrap.BootstrapDropDown.(BootstrapDropDown.java:87)
4

2 回答 2

0

这是xml中使用的代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:components="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"

tools:context=".MainActivity" >

<com.beardedhen.androidbootstrap.BootstrapDropDown
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:bootstrapBrand="regular"
    app:roundedCorners="true"
    app:dropdownResource="@array/bootstrap_dropdown_example_data"
  >

</com.beardedhen.androidbootstrap.BootstrapDropDown>

</RelativeLayout>
于 2017-11-22T10:12:25.657 回答
0

嘿,我相信我有类似的问题。我所做的是将一个字符串数组添加到 project/app/res/values/strings.xml 中。

像这样将字符串数组添加到您的 strings.xml 中:

<resources>
...
<string-array name="bootstap_dropdown_example_data">
    <item>item1</item>
    <item>item2</item>
    <item>item3</item>
</string-array>
</resources>

确保“字符串数组名称”与您的 XML 文件中的数组名称匹配 app:dropdownResource="@array/..." 确保您的 strings.xml 数组中有项目。

让我知道这是否适合您!

于 2018-01-27T02:18:39.747 回答