edittext-mask
edittext-mask copied to clipboard
Error when add 2 editText in one xml file
I am trying to use 2 MaskedEditText but wheb run applicaiton it shows errors
Error code
java.lang.RuntimeException: Unable to start activity ComponentInfo{uz.xb.istemolkredit/uz.xb.istemolkredit.ui.MainActivity}: android.view.InflateException: Binary XML file line #65: Binary XML file line #65: Error inflating class br.com.sapereaude.maskedEditText.MaskedEditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3092)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3235)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6990)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Caused by: android.view.InflateException: Binary XML file line #65: Binary XML file line #65: Error inflating class br.com.sapereaude.maskedEditText.MaskedEditText
Caused by: android.view.InflateException: Binary XML file line #65: Error inflating class br.com.sapereaude.maskedEditText.MaskedEditText
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
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.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.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.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.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 androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at uz.xb.istemolkredit.ui.MainActivity.onCreate(MainActivity.java:104)
at android.app.Activity.performCreate(Activity.java:7326)
at android.app.Activity.performCreate(Activity.java:7317)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3235)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
2019-09-23 15:04:25.725 30583-30583/? E/AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6990)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
at br.com.sapereaude.maskedEditText.MaskedEditText.generatePositionArrays(MaskedEditText.java:205)
at br.com.sapereaude.maskedEditText.MaskedEditText.cleanUp(MaskedEditText.java:122)
at br.com.sapereaude.maskedEditText.MaskedEditText.
XML code
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/passportSerial_inputLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/_4dp"
android:background="@drawable/rectangle_message_white"
android:hint="@string/passport_serial"
android:padding="@dimen/_4dp"
android:textColorHint="@color/colorBlack"
android:theme="@style/textInputLayout">
<br.com.sapereaude.maskedEditText.MaskedEditText
android:id="@+id/passportSerial_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:ems="4"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLength="2"
android:padding="@dimen/_8dp"
android:textColor="@color/colorBlack"
android:textColorHint="#66161616"
android:keep_hint="true"
android:textStyle="bold" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/passportNumber_inputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rectangle_message_white"
android:hint="@string/passport_number"
android:padding="@dimen/_4dp"
android:textColorHint="@color/colorBlack"
android:theme="@style/textInputLayout">
<br.com.sapereaude.maskedEditText.MaskedEditText
android:id="@+id/passportNumber_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:imeOptions="actionNext"
android:inputType="numberDecimal"
android:maxLength="7"
android:padding="@dimen/_8dp"
android:textColor="@color/colorBlack"
android:textColorHint="#66161616"
android:keep_hint="true"
android:textStyle="bold" />
</com.google.android.material.textfield.TextInputLayout>
I have the same problem even with one edit text only. any progress?
I have the same problem even with one edit text only. any progress?
No progress. Still have this error, but with two edittext. It works well with one edittext.
The same error happened to me even with just one EditText
implemented, in my case I was importing mask
attribute
from the wrong name space (was importing it from tools
while it should be from res-auto
)
For your case, I don't see mask
attribute
, have u tried including it in your xml
?
include xmlns:app="http://schemas.android.com/apk/res-auto"
in your root tag, then for your EditText
include for example (per your needs):
app:allowed_chars="1234567890"
app:mask="+7(###)###-##-##"
As I understood from debugging the code, app:mask
is mandatory.
PS: Now I have two EditText
's in one xml
and one parent
and it works fine.
The same error happened to me even with just one
EditText
implemented, in my case I was importingmask
attribute
from the wrong name space (was importing it fromtools
while it should be fromres-auto
)For your case, I don't see
mask
attribute
, have u tried including it in yourxml
?include
xmlns:app="http://schemas.android.com/apk/res-auto"
in your root tag, then for yourEditText
include for example (per your needs):app:allowed_chars="1234567890" app:mask="+7(###)###-##-##"
As I understood from debugging the code,
app:mask
is mandatory.PS: Now I have two
EditText
's in onexml
and oneparent
and it works fine.
Okay, that's makes sense. I will check it.