【问题标题】:App freeze on keypad open with android studio 3.1 update使用 android studio 3.1 更新打开键盘上的应用程序冻结
【发布时间】:2018-03-29 12:59:48
【问题描述】:

应用在更新前运行良好。 每当我点击某些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 nullpointerexception freeze android-keypad android-studio-3.1


【解决方案1】:

我今天也突然在运行 Android 7.1.1 的 Nexus 6P 中开始出现这种崩溃。我什至回到项目中一个我知道正在工作的稳定分支时,同样的事情还在继续发生。唯一的区别是我在 Edit Configurations -> app -> Profiling 中启用了高级分析,我禁用了它,一切都恢复正常了。在我的情况下,崩溃是在键盘关闭时。希望对您有所帮助。

【讨论】:

  • 对于一个稳定的版本,它还没有经过测试:-(这对我有用。我在更新 AS 的过程中隐约记得一些关于这件事的事情,我认为永远不会记得或想到它。感谢您提出那个答案。
  • 禁用高级分析后它可以工作,我很想知道根本原因!如果有人知道,请与我们分享。
【解决方案2】:

这是 Android Studio 3.1 的高级分析功能中的一个错误,现在回滚到 3.0 为我解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    • 2013-01-19
    • 1970-01-01
    • 2017-10-18
    • 2018-01-15
    • 2023-01-30
    相关资源
    最近更新 更多