0
votes

Hello my professor cannot figure this out so I figured I would post here. I am trying to make an app that shows temperatures and when the seek bar gets to a certain temp I want to have a different image appear in an imageView. When i test the app and the seek bar gets past 40 the app forecloses. Can anyone tell me why that is?

SeekBar seekBar;
TextView f, c;
ImageView i;
int progress_value;


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

    seekBar = (SeekBar)findViewById(R.id.seekBar);
    seekBar.setMax(200);
    f = (TextView)findViewById(R.id.f);
    c = (TextView)findViewById(R.id.c);
    i = (ImageView)findViewById(R.id.imageView);

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            progress_value = progress;

            f.setText(" " + progress_value);
            c.setText(" " + .55 * (progress_value - 32));

            if (progress_value <= 40){
                i.setImageResource(R.drawable.cold);
            }
            else if (progress_value > 40 && progress_value < 90){
                i.setImageResource(R.drawable.justright);
            }
            else{
                i.setImageResource(R.drawable.hot);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

}

}

09/26 23:21:56: Launching app $ adb push C:\Users\aniel\AndroidStudioProjects\HomeWork#2\app\build\outputs\apk\app-debug.apk /data/local/tmp/com.example.aniel.homework2 $ adb shell pm install -r "/data/local/tmp/com.example.aniel.homework2" Success

$ adb shell am start -n "com.example.aniel.homework2/com.example.aniel.homework2.Tempature" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Client not ready yet..Waiting for process to come online Waiting for process to come online Waiting for process to come online Waiting for process to come online Waiting for process to come online Connected to process 2373 on device emulator-5554 W/gralloc_ranchu: Gralloc pipe failed

              [ 09-26 23:22:05.204  2373: 2373 D/         ]
              HostConnection::get() New Host Connection established 0x982851c0, tid 2373

I/OpenGLRenderer: Initialized EGL, version 1.4 D/OpenGLRenderer: Swap behavior 1 D/AndroidRuntime: Shutting down VM

              --------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.example.aniel.homework2, PID: 2373
                  java.lang.RuntimeException: Canvas: trying to draw too large(241864000bytes) 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:545)
                      at android.widget.ImageView.onDraw(ImageView.java:1286)
                      at android.view.View.draw(View.java:17068)
                      at android.view.View.updateDisplayListIfDirty(View.java:16050)
                      at android.view.View.draw(View.java:16834)
                      at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
                      at android.view.View.updateDisplayListIfDirty(View.java:16045)
                      at android.view.View.draw(View.java:16834)
                      at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
                      at android.view.View.updateDisplayListIfDirty(View.java:16045)
                      at android.view.View.draw(View.java:16834)
                      at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
                      at android.view.View.updateDisplayListIfDirty(View.java:16045)
                      at android.view.View.draw(View.java:16834)
                      at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
                      at android.view.View.updateDisplayListIfDirty(View.java:16045)
                      at android.view.View.draw(View.java:16834)
                      at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
                      at android.view.View.updateDisplayListIfDirty(View.java:16045)
                      at android.view.View.draw(View.java:16834)
                      at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
                      at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
                      at android.view.View.draw(View.java:17071)
                      at com.android.internal.policy.DecorView.draw(DecorView.java:751)
                      at android.view.View.updateDisplayListIfDirty(View.java:16050)
                      at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:656)
                      at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:662)
                      at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:770)
                      at android.view.ViewRootImpl.draw(ViewRootImpl.java:2796)
                      at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2604)
                      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2211)
                      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246)
                      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6301)
                      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
                      at android.view.Choreographer.doCallbacks(Choreographer.java:683)
                      at android.view.Choreographer.doFrame(Choreographer.java:619)
                      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
                      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:6077)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Application terminated.
2
Can you share your log messages ? What is the exception that you are getting ?nishith kumar
Can you share log ?Arslan
Please paste the exception or does you app goes to background for a long time ?Ashish Rawat
Sorry I am new to this how do I share my logs in stackoverflow?Aniello Scartozzi
The problem is clearly mentioned in the first thee lines of the posted logcat. So please read them.greenapps

2 Answers

0
votes

Drawable images cant be changed at run time. Because of this your app is crashing. I would like to propose a fix. Try converting your drawable images to bitmaps and then change bitmaps on your required condition.

0
votes

Use Picasso, something like this worked for me

ImageView img1 = (ImageView)findViewById(R.id.chamb_img);
Picasso.with(this).load(R.drawable.h).resize(75,75).into(img1);