Error trying to add an image as the background of a button

0

A few days ago, Android Studio indicated that it had updates that were available ...

I had already finished an application for some time and it was ready to be published and talz, I just needed the license of Google Play that I needed to buy.

I bought the license and returned to Android Studio to implement ads (adMob) and generate the key.

I was invented to implement the gradle build update (it was "optional") in the app and it immediately stopped working ...

So I was redoing it until I needed to add backgrounds to the application buttons, just like I did in the other one and for some reason the app does not start and no error is accused beyond that:

07-01 23:40:09.925 6690-6690/genesysgeneration.ruleoftree E/AndroidRuntime: FATAL EXCEPTION: main
                                                                            Process: genesysgeneration.ruleoftree, PID: 6690
                                                                            java.lang.RuntimeException: Canvas: trying to draw too large(146963896bytes) bitmap.
                                                                                at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
                                                                                at android.graphics.Canvas.drawBitmap(Canvas.java:1415)
                                                                                at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:528)
                                                                                at android.view.View.getDrawableRenderNode(View.java:17428)
                                                                                at android.view.View.drawBackground(View.java:17364)
                                                                                at android.view.View.draw(View.java:17176)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:16167)
                                                                                at android.view.View.draw(View.java:16951)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
                                                                                at android.view.View.draw(View.java:17188)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:16167)
                                                                                at android.view.View.draw(View.java:16951)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:16162)
                                                                                at android.view.View.draw(View.java:16951)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:16162)
                                                                                at android.view.View.draw(View.java:16951)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:16162)
                                                                                at android.view.View.draw(View.java:16951)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:16162)
                                                                                at android.view.View.draw(View.java:16951)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3727)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3513)
                                                                                at android.view.View.draw(View.java:17188)
                                                                                at com.android.internal.policy.DecorView.draw(DecorView.java:753)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:16167)
                                                                                at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:648)
                                                                                at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:654)
                                                                                at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:762)
                                                                                at android.view.ViewRootImpl.draw(ViewRootImpl.java:2800)
                                                                                at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2608)
                                                                                at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2215)
                                                                                at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254)
                                                                                at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6337)
                                                                                at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
                                                                                at android.view.Choreographer.doCallbacks(Choreographer.java:686)
                                                                                at android.view.Choreographer.doFrame(Choreographer.java:621)
                                                                                at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
                                                                                at android.os.Handler.handleCallback(Handler.java:751)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                at android.os.Looper.loop(Looper.java:154)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Withouttheimplementationofthebackgroundsthesameworks,itisaddanyimageanditdoesnotworkanymore.

Partoftheactivitycode:

package genesysgeneration.ruleoftree;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

public class MainActivity01 extends AppCompatActivity implements View.OnClickListener{

    private EditText et01, et02, et03;
    private TextView tv01/*, tvTest*/;
    private double l01, l02, l03, equalizer, lxx;
    private ImageView btnChange01, btnCompras, btnMoeda, btnInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main01);

        tv01=(TextView)findViewById(R.id.tv01);
        tv01.setText(String.valueOf(0));

        l01=0;
        l02=0;
        l03=0;
        lxx=0;

        et01=(EditText)findViewById(R.id.et01);
        et02=(EditText)findViewById(R.id.et02);
        et03=(EditText)findViewById(R.id.et03);

        addValuesDouble();

        btnChange01=(ImageView)findViewById(R.id.btnChange01);
        Picasso.with().load(R.drawable.setas_03).into(btnChange01);
        btnChange01.setOnClickListener(this);

        btnCompras=(ImageView)findViewById(R.id.btnCompras);
        btnCompras.setOnClickListener(this);

        btnMoeda=(ImageView)findViewById(R.id.btnMoeda);
        btnMoeda.setOnClickListener(this);

        btnInfo=(ImageView)findViewById(R.id.btnInfo);
        btnInfo.setOnClickListener(this);

    }
    
}
    
asked by anonymous 02.07.2017 / 02:02

1 answer

1

You seem to be carrying a very large image on the button (by error message). Why not swap the button for an imageView and use Picasso to load the image on it? It does all the decoding of the image to load it on the screen.

Install in Gradle:

compile 'com.squareup.picasso:picasso:2.5.2'

And use in the code:

Picasso.with(context).load(R.drawable.image).into(imageView);
    
02.07.2017 / 14:05