ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

用android studio 3.1更新打开键盘上的App冻结

2019-05-22 17:14:18  阅读:216  来源: 互联网

标签:android nullpointerexception freeze android-keypad android-studio-3-1


应用程序在更新前工作正常.
每当我点击一些EditTextcursor闪烁几秒钟,比应用程序冻结并卡住.

login_activity.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    tools:context=".activities.LoginActivity">

       <app.com.skribl.utils.customviews.CustomTILayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_20sdp"
                android:gravity="center"
                android:textColorHint="@color/orange"
                app:customFont="Raleway-Regular.ttf">

                <app.com.skribl.utils.customviews.CustomEditText
                    android:id="@+id/et_email"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:hint="@string/prompt_email1"
                    android:inputType="textEmailAddress"
                    android:maxLines="1"
                    android:padding="@dimen/x13dp"
                    android:singleLine="true"
                    android:textColor="@color/blue_dark"
                    android:textSize="14sp"
                    app:customFont="Roboto-Light.ttf" />
            </app.com.skribl.utils.customviews.CustomTILayout>

            <app.com.skribl.utils.customviews.CustomTILayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_5sdp"
                android:gravity="center"
                android:textColorHint="@color/orange"
                app:customFont="Raleway-Regular.ttf">

                <app.com.skribl.utils.customviews.CustomEditText
                    android:id="@+id/et_password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:hint="@string/prompt_password"
                    android:inputType="textPassword"
                    android:maxLines="1"
                    android:padding="@dimen/x13dp"
                    android:singleLine="true"
                    android:textColor="@color/blue_dark"
                    android:textSize="14sp"
                    app:customFont="Roboto-Light.ttf" />

            </app.com.skribl.utils.customviews.CustomTILayout>

            <app.com.skribl.utils.customviews.CustomButton
                android:id="@+id/btn_login"
                style="?android:textAppearanceSmall"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_20sdp"
                android:background="@drawable/round_corner_btn"
                android:padding="@dimen/x15dp"
                android:text="@string/action_sign_in_short"
                android:textColor="@color/white"
                android:textSize="@dimen/text_size_moderate"
                android:textStyle="bold"
                app:customFont="Raleway-Regular.ttf" />

        </LinearLayout>

CustomEditText.java

public class CustomEditText extends EditText {
    private static final String TAG = "EditText";

    public CustomEditText(Context context) {
        super(context);
    }

    public CustomEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        setCustomFont(context, attrs);
    }

    public CustomEditText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setCustomFont(context, attrs);
    }

    private void setCustomFont(Context ctx, AttributeSet attrs) {
        TypedArray a = ctx.obtainStyledAttributes(attrs, R.styleable.CustomTextView);
        String customFont = a.getString(R.styleable.CustomTextView_customFont);
        setCustomFont(ctx, customFont);
        a.recycle();
    }


    public boolean setCustomFont(Context ctx, String fontName) {
        Typeface typeface = null;
        try {
            if(fontName == null){
                fontName = Constants.DEFAULT_FONT_NAME_FOR_ET;
            }
            typeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/" + fontName);
        } catch (Exception e) {
            Log.e(TAG, "Unable to load typeface: "+e.getMessage());
            return false;
        }

        setTypeface(typeface);

        return true;
    }

    protected void setSpan_internal(Object span, int start, int end, int flags) {
        final int textLength = getText().length();
        ((Editable) getText()).setSpan(span, start, Math.min(end, textLength), flags);
    }

    protected void setCursorPosition_internal(int start, int end) {
        final int textLength = getText().length();
        Selection.setSelection(((Editable) getText()), Math.min(start, textLength), Math.min(end, textLength));
    }

}

到目前为止这是日志:

java.lang.NullPointerException: Attempt to invoke interface method 'void android.view.inputmethod.InputConnection.closeConnection()' on a null object reference at android.view.inputmethod.InputConnectionWrapper.closeConnection(InputConnectionWrapper.java:270)
        at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:553)
        at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:93)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

解决方法:

在运行Android 7.1.1的Nexus 6P中,我今天突然开始发生这次崩溃.我甚至回到项目的一个稳定的分支,我知道它正在工作,同样继续发生.唯一的区别是我在编辑配置中启用了高级分析 – > app – >分析,我禁用它,一切都恢复正常.在我的情况下,崩溃是键盘关闭时.希望这可以帮到你.

标签:android,nullpointerexception,freeze,android-keypad,android-studio-3-1
来源: https://codeday.me/bug/20190522/1153064.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有