我正在尝试创建我创建的自定义 AppCompactEditText。我还创建了一个示例应用程序来测试我的自定义组件。但是,当我从示例应用程序的 xml 调用/输入我的自定义编辑文本时,它崩溃并给出错误java.lang.RuntimeException: Unable to start activity ComponentInfo
这是我的代码
class InputFields: AppCompatEditText{
private var mContext: Context
private var mAttrs: AttributeSet?
private var mDefStyleAttr: Int? = 0
constructor(context: Context) : super(context) {
mContext = context
mAttrs = null
init()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
mContext = context
mAttrs = attrs
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
mContext = context
mAttrs = attrs
mDefStyleAttr = defStyleAttr
init()
}
private fun init(){
// this function initializes all the attributes
// however when I debug it , it doesn't reach this block of code at all.
}
}
我在这样的示例应用程序中调用它
<com.sample.inputfields.InputFields //line #26 ..The Error occurs on this line
android:id="@+id/input_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
/>
这是我得到的错误
05-08 11:07:24.130 31892-31892/? E/Zygote: isWhitelistProcess - Process is Whitelisted
05-08 11:07:24.133 31892-31892/? E/libpersona: scanKnoxPersonas
Couldn't open the File - /data/system/users/0/personalist.xml - No such file or directory
05-08 11:07:30.079 31892-31892/com.sample.screenpatterns E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sample.screenpatterns, PID: 31892
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sample.screenpatterns/com.sample.sample.activities.InputFieldsSample}: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.sample.inputfields.InputFields
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2955)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.sample.inputfields.InputFields
Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class com.sample.inputfields.InputFields
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sample.inputfields.InputFields" on path: DexPathList[[zip file "/data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/base.apk", zip file "/data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/split_lib_dependencies_apk.apk", zip file "/data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/split_lib_resources_apk.apk", zip file "/data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/split_lib_slice_0_apk.apk", zip file "/data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/split_lib_slice_1_apk.apk", zip file "/data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/split_lib_slice_2_apk.apk", zip file "/data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/split_lib_slice_3_apk.apk", zip file "/data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/split_lib_slice_4_apk.apk", zip file "/data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/split_lib_slice_5_apk.apk", zip file "/data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/split_lib_slice_6_apk.apk", zip file "/data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/split_lib_slice_7_apk.apk", zip file "/data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/split_lib_slice_8_apk.apk", zip file "/data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/lib/arm64, /system/lib64, /system/vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
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.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
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:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
05-08 11:07:30.081 31892-31892/com.sample.screenpatterns E/AndroidRuntime: at com.sample.sample.activities.InputFieldsSample.onCreate(InputFieldsSample.kt:12)
at android.app.Activity.performCreate(Activity.java:7174)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Suppressed: java.io.IOException: No original dex files found for dex location (arm64) /data/app/com.sample.screenpatterns-zfrxyrSPMGl2-va6c2wybw==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:353)
at dalvik.system.DexFile.<init>(DexFile.java:100)
at dalvik.system.DexFile.<init>(DexFile.java:74)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:337)
at dalvik.system.DexPathList.<init>(DexPathList.java:157)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:69)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:36)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:678)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:711)
at android.app.LoadedApk.getResources(LoadedApk.java:944)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2303)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5937)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1764)
... 6 more
我也以正确的方式导入了自定义组件/模块。有人可以帮我弄清楚我做错了什么。提前致谢。