Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Erro ao rolar lista de alunos

Olá, quando faço a navegação pela lista de alunos o aplicativo da agenda simplesmente para. O que pode ser? Segue erro abaixo:

07-26 00:36:00.241 2338-2338/br.com.alura.agenda E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/Android/data/br.com.alura.agenda/files/Pictures/JPEG_20170724_220306_1774942816.jpg (No such file or directory)
07-26 00:36:00.242 2338-2338/br.com.alura.agenda E/InputEventReceiver: Exception dispatching input event.
07-26 00:36:00.242 2338-2338/br.com.alura.agenda D/AndroidRuntime: Shutting down VM
07-26 00:36:00.257 2338-2338/br.com.alura.agenda E/AndroidRuntime: FATAL EXCEPTION: main
                                                                   Process: br.com.alura.agenda, PID: 2338
                                                                   java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
                                                                       at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:658)
                                                                       at br.com.alura.agenda.adapter.AlunosAdapter.getView(AlunosAdapter.java:87)
                                                                       at android.widget.AbsListView.obtainView(AbsListView.java:2362)
                                                                       at android.widget.ListView.makeAndAddView(ListView.java:1970)
                                                                       at android.widget.ListView.fillDown(ListView.java:704)
                                                                       at android.widget.ListView.fillGap(ListView.java:668)
                                                                       at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5185)
                                                                       at android.widget.ListView.trackMotionScroll(ListView.java:1889)
                                                                       at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3567)
                                                                       at android.widget.AbsListView.onTouchMove(AbsListView.java:3976)
                                                                       at android.widget.AbsListView.onTouchEvent(AbsListView.java:3801)
                                                                       at android.view.View.dispatchTouchEvent(View.java:9943)
                                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2663)
                                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2344)
                                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
                                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
                                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
                                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
                                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
                                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
                                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                                       at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
                                                                       at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
                                                                       at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:411)
                                                                       at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1810)
                                                                       at android.app.Activity.dispatchTouchEvent(Activity.java:3061)
                                                                       at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
                                                                       at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:373)
                                                                       at android.view.View.dispatchPointerEvent(View.java:10163)
                                                                       at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4434)
                                                                       at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4302)
                                                                       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3849)
                                                                       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3902)
                                                                       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3868)
                                                                       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3995)
                                                                       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3876)
                                                                       at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4052)
                                                                       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3849)
                                                                       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3902)
                                                                       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3868)
                                                                       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3876)
                                                                       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3849)
                                                                       at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6210)
                                                                       at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6184)
                                                                       at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6145)
                                                                       at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6313)
                                                                       at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
07-26 00:36:00.257 2338-2338/br.com.alura.agenda E/AndroidRuntime:     at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
                                                                       at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
                                                                       at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6284)
                                                                       at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6336)
                                                                       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
                                                                       at android.view.Choreographer.doCallbacks(Choreographer.java:683)
                                                                       at android.view.Choreographer.doFrame(Choreographer.java:613)
                                                                       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)
07-26 00:36:00.259 1542-3352/system_process W/ActivityManager:   Force finishing activity br.com.alura.agenda/.ListaAlunosActivity
07-26 00:36:00.276 1247-1298/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
07-26 00:36:00.305 1247-1973/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
3 respostas

Oi Victor, tudo bem?

Pelo o que o erro indica, significa que a imagem /storage/emulated/0/Android/data/br.com.alura.agenda/files/Pictures/JPEG_20170724_220306_1774942816.jpg não existe no seu dispositivo. Você pode lidar com esse tipo de situação da seguinte maneira:

  • Tratar via try/catch, então, quando for disparado a exception FileNotFoundException você toma alguma ação, no caso, pode simplesmente usar o person.png como alternativa caso o a exception ocorra.

[]s

Olá Alex. Tentei fazer o Try/Catch como você orientou, mas os parametros do catch estavam com aquela linha vermelha em baixo, indicando como erro(abaixo o try/catch escrito no código). Há outra sugestão?

ImageView campoFoto = (ImageView) view.findViewById(R.id.item_foto);
        String caminhoFoto;
        try{
            caminhoFoto =  aluno.getCaminhoFoto();
        }catch(FileNotFoundException e){

        }
solução!

Acho que resolvi. Fiz um delete sem clausula where na tabela de Alunos e fiz testes e funcionou. Obrigado Alex!