例外' android.graphics.drawable.RippleDrawable',从方法android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering引用

时间:2017-10-31 04:21:58

标签: android

我正在设计一个Android应用程序。我的应用程序在上面的21 API上工作正常,但是当我开始在API 18上测试它时不幸停止了。在登录活动的开始应用程序正在停止。当我在Edittext应用程序中输入时,不幸停止。 以下是我的代码。

    package com.example.kiran.kioskapp.activity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.kiran.kioskapp.MyApplication;
import com.example.kiran.kioskapp.R;

import com.example.kiran.kioskapp.helper.Helper;
import com.example.kiran.kioskapp.helper.SessionManager;
import com.example.kiran.kioskapp.utils.APIUtils;
import com.example.kiran.kioskapp.data.remote.Webservice;
import com.example.kiran.kioskapp.service.ConnectivityReceiver;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class LoginActivity extends AppCompatActivity implements ConnectivityReceiver.ConnectivityReceiverListener {

    Button ibtnLogin;
    EditText iedtClientId, iedtDeviceCode;
    String strDeviceCode;
    long clientId;
    Helper helper;
    Webservice webservice;
    SessionManager sessionManager;
    Toolbar toolbar;
    ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        initToolbar();
        checkConnection();
        sessionManager = new SessionManager(LoginActivity.this);
        helper = new Helper(LoginActivity.this);
        webservice = APIUtils.getWebsevice(Webservice.class);
        //if already logged in then edirect to HomeActivity
        Log.d("TAG", "session " + sessionManager.isLoggedIn());
        iedtClientId = (EditText) findViewById(R.id.edt_clientid);
        iedtDeviceCode = (EditText) findViewById(R.id.edt_device_code);
        ibtnLogin = (Button) findViewById(R.id.btn_login);

        ibtnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (checkValidation()) {
                    clientId = Long.parseLong(iedtClientId.getText().toString().trim());
                    strDeviceCode = iedtDeviceCode.getText().toString().trim();
                    strDeviceCode = strDeviceCode.toUpperCase();
                    webservice.isAuthenticate(clientId, strDeviceCode).enqueue(new Callback<Boolean>() {
                        @Override
                        public void onResponse(Call<Boolean> call, Response<Boolean> response) {

                            if (response.code() == 200) {
                                ProgressDialog dialog = ProgressDialog.show(LoginActivity.this, getString(R.string.progess_title), getString(R.string.progess_message), false, false);
                                dialog.show();
                                sessionManager.createLoginSession(clientId, strDeviceCode);
                                Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
                                startActivity(intent);
                                finish();
                            } else
                                Helper.showCustomToast(LoginActivity.this, getString(R.string.wrong_credentials));
                        }

                        @Override
                        public void onFailure(Call<Boolean> call, Throwable t) {
                            Helper.showCustomToast(LoginActivity.this, getString(R.string.network_error));
                        }
                    });

                }//if checkvalidation()
            }

        });
    }


    public boolean checkValidation() {

        boolean valid = true;
        if (iedtClientId.getText().toString().trim().isEmpty()) {
            iedtClientId.setError(getString(R.string.client_error));
            valid = false;
        } else {
            iedtClientId.setError(null);
        }

        if (iedtDeviceCode.getText().toString().trim().isEmpty()) {
            iedtDeviceCode.setError(getString(R.string.device_error));
            valid = false;
        } else {
            iedtDeviceCode.setError(null);
        }
        return valid;
    }
    private void initToolbar() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("");//reset default title
        imageView = (ImageView) toolbar.findViewById(R.id.img_refresh);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


            }
        });
    }

    private void checkConnection() {
        boolean isConnected = ConnectivityReceiver.isConnected();
        showSnackBar(isConnected);
        if (isConnected == true) {
            String recName = ConnectivityReceiver.getConnectedWifiInfo();
            int level = ConnectivityReceiver.getLevel();
            Log.d("TAG", recName + " " + level);
        }

    }

    @Override
    protected void onResume() {
        super.onResume();
        MyApplication.getInstance().setConnectivityListener(this);

    }


    void showSnackBar(boolean value) {
        String message;
        if (value == true)
            message = "Good! Connected to Internet";
        else
            message = "Sorry! Not connected to internet";
        View mView = findViewById(android.R.id.content);
        Snackbar.make(mView, message, Snackbar.LENGTH_LONG)
                .show();
    }

    @Override
    public void onNetworkConnectionChanged(boolean isConnected) {
        showSnackBar(isConnected);
    }


}

它显示了各种例外。

 Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
10-31 00:18:57.991 2105-2105/com.example.kiran.kioskapp E/InputEventReceiver: Exception dispatching input event.
10-31 00:18:57.991 2105-2105/com.example.kiran.kioskapp E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
10-31 00:18:57.991 2105-2105/com.example.kiran.kioskapp E/MessageQueue-JNI: java.lang.IndexOutOfBoundsException
                                                                                at android.graphics.Paint.getTextRunAdvances(Paint.java:1777)
                                                                                at android.text.TextLine.handleText(TextLine.java:747)
                                                                                at android.text.TextLine.handleRun(TextLine.java:898)
                                                                                at android.text.TextLine.measureRun(TextLine.java:414)
                                                                                at android.text.TextLine.measure(TextLine.java:293)
                                                                                at android.text.Layout.getHorizontal(Layout.java:852)
                                                                                at android.text.Layout.getHorizontal(Layout.java:830)
                                                                                at android.text.Layout.getPrimaryHorizontal(Layout.java:805)
                                                                                at android.text.Layout.getPrimaryHorizontal(Layout.java:795)
                                                                                at android.text.Layout.getOffsetForHorizontal(Layout.java:1116)
                                                                                at android.widget.TextView.getOffsetAtCoordinate(TextView.java:8520)
                                                                                at android.widget.TextView.getOffsetForPosition(TextView.java:8496)
                                                                                at android.widget.Editor$SelectionModifierCursorController.onTouchEvent(Editor.java:3597)
                                                                                at android.widget.Editor.onTouchEvent(Editor.java:1017)
                                                                                at android.widget.TextView.onTouchEvent(TextView.java:7601)
                                                                                at android.view.View.dispatchTouchEvent(View.java:7384)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                                at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                                at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                                at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1966)
                                                                                at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1418)
                                                                                at android.app.Activity.dispatchTouchEvent(Activity.java:2424)
                                                                                at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
                                                                                at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
                                                                                at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1914)
                                                                                at android.view.View.dispatchPointerEvent(View.java:7564)
                                                                                at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883)
                                                                                at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778)
                                                                                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                                at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                                at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
                                                                                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
                                                                                at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
                                                                                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                                at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                                at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
                                                                                at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                                at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5419)
                                                                                at android.view.ViewRootI
10-31 00:18:58.001 2105-2105/com.example.kiran.kioskapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                          java.lang.IndexOutOfBoundsException
                                                                              at android.graphics.Paint.getTextRunAdvances(Paint.java:1777)
                                                                              at android.text.TextLine.handleText(TextLine.java:747)
                                                                              at android.text.TextLine.handleRun(TextLine.java:898)
                                                                              at android.text.TextLine.measureRun(TextLine.java:414)
                                                                              at android.text.TextLine.measure(TextLine.java:293)
                                                                              at android.text.Layout.getHorizontal(Layout.java:852)
                                                                              at android.text.Layout.getHorizontal(Layout.java:830)
                                                                              at android.text.Layout.getPrimaryHorizontal(Layout.java:805)
                                                                              at android.text.Layout.getPrimaryHorizontal(Layout.java:795)
                                                                              at android.text.Layout.getOffsetForHorizontal(Layout.java:1116)
                                                                              at android.widget.TextView.getOffsetAtCoordinate(TextView.java:8520)
                                                                              at android.widget.TextView.getOffsetForPosition(TextView.java:8496)
                                                                              at android.widget.Editor$SelectionModifierCursorController.onTouchEvent(Editor.java:3597)
                                                                              at android.widget.Editor.onTouchEvent(Editor.java:1017)
                                                                              at android.widget.TextView.onTouchEvent(TextView.java:7601)
                                                                              at android.view.View.dispatchTouchEvent(View.java:7384)
                                                                              at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                              at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                              at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                              at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                              at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                              at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                              at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                              at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                              at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                              at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                              at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                              at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                              at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                              at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                              at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                              at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                              at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
                                                                              at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
                                                                              at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1966)
                                                                              at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1418)
                                                                              at android.app.Activity.dispatchTouchEvent(Activity.java:2424)
                                                                              at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
                                                                              at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
                                                                              at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1914)
                                                                              at android.view.View.dispatchPointerEvent(View.java:7564)
                                                                              at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883)
                                                                              at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778)
                                                                              at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                              at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                              at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                              at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
                                                                              at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
                                                                              at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
                                                                              at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                              at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
                                                                              at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
                                                                              at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
                                                                              at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
                                                                              at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5419)
                                                                            at an

                                                                          [ 10-31 00:18:58.011  1442: 1567 D/         ]
                                                                          HostConnection::get() New Host Connection established 0xb7d793f0, tid 1567

...

错误正是我没有得到的地方。请帮忙。

1 个答案:

答案 0 :(得分:0)

  

试试这个,检查Android Api版本是否高于19然后应用涟漪效应,否则没有涟漪效应

private void setBackgrounds(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            forgot.setBackgroundDrawable(getResources().getDrawable(R.drawable.tv_ripple));

        }
  

tv_ripple.xml

 <?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:color="#55000000"
    tools:targetApi="lollipop">
    <item android:id="@android:id/mask">
        <shape android:shape="rectangle">
            <solid android:color="#88000000" />
            <corners android:radius="5dp"/>
        </shape>
    </item>
</ripple>