MaskedEditText使用View.isInEditMode()

时间:2015-05-29 21:25:48

标签: java android

使用maskedEditText库时出现以下错误:

enter image description here

我下载了库,然后点击现有代码中的文件 - > New-> Other-> Android 项目>添加文件夹,将复制项目复制到工作区

然后我将库文件夹添加到我的项目中:

enter image description here

当我跑步时,我有ClassNotFoundException

我的xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:mask="http://schemas.android.com/apk/res/com.example.pppp"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.pppp.MainActivity" >

    <br.com.sapereaude.maskedEditText.MaskedEditText 
                        android:id="@+id/phoneNumber"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="3dp"
                        android:background="@null"
                        android:inputType="number"
                        mask:mask="(###) ###-##-##"
                    >
                    </br.com.sapereaude.maskedEditText.MaskedEditText>

</RelativeLayout>

错误

05-30 10:10:38.423: E/AndroidRuntime(32526): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pppp/com.example.pppp.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class br.com.sapereaude.maskedEditText.MaskedEditText
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2077)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.app.ActivityThread.access$600(ActivityThread.java:134)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.os.Looper.loop(Looper.java:154)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.app.ActivityThread.main(ActivityThread.java:4624)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at java.lang.reflect.Method.invokeNative(Native Method)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at java.lang.reflect.Method.invoke(Method.java:511)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at dalvik.system.NativeStart.main(Native Method)
05-30 10:10:38.423: E/AndroidRuntime(32526): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class br.com.sapereaude.maskedEditText.MaskedEditText
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.view.LayoutInflater.createView(LayoutInflater.java:608)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:682)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:741)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.view.LayoutInflater.inflate(LayoutInflater.java:491)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at com.example.pppp.MainActivity.onCreate(MainActivity.java:13)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.app.Activity.performCreate(Activity.java:4479)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2041)
05-30 10:10:38.423: E/AndroidRuntime(32526):    ... 11 more
05-30 10:10:38.423: E/AndroidRuntime(32526): Caused by: java.lang.reflect.InvocationTargetException
05-30 10:10:38.423: E/AndroidRuntime(32526):    at java.lang.reflect.Constructor.constructNative(Native Method)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-30 10:10:38.423: E/AndroidRuntime(32526):    at android.view.LayoutInflater.createView(LayoutInflater.java:588)
05-30 10:10:38.423: E/AndroidRuntime(32526):    ... 22 more
05-30 10:10:38.423: E/AndroidRuntime(32526): Caused by: java.lang.NoClassDefFoundError: br.com.sapereaude.maskedEditText.R$styleable
05-30 10:10:38.423: E/AndroidRuntime(32526):    at br.com.sapereaude.maskedEditText.MaskedEditText.<init>(MaskedEditText.java:43)

1 个答案:

答案 0 :(得分:0)

尝试将名称空间更改为&#34; MaskedEditText.MaskedEditText&#34;。我们可以在&#34; References / MaskedEditText&#34;中看到命名空间。 示例

        <MaskedEditText.MaskedEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                mask:mask="+# (###) ##-##"
                android:id="@+id/email" />