• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Android studio App crashes when image is imported manually from Gallery or Camera app

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So my application is an Image to text and text-to-speech app. The idea is to scan text from any source and it is read out to the user. The basic functionality of the app is working, when I click on "Capture Image" on the main screen, it opens the camera, takes a pic, and extracts text. But I also added another function where the user can manually add pictures from his gallery by clicking on the gallery icon.

So the problem is when I select the gallery and choose my own image, it won't add to the main image view canvas, instead, it crashes the application. There is no error in the code, but it just won't run.

Here are 20-second clips I have attached on Google Drive to show you the precise problem for a better understanding for you all. I’m very close!

https://drive.google.com/drive/folders/18oCeFkVEvi1xPv_O4DEI3EZz0TtVyZ36?usp=sharing

Kindly please let me know what the problem is, as Android studio does not give any warnings or errors when the project is run.

Let me know what part of the code do you need, because when I paste the code here it says it is too long.

Gallery-1.png
[Thumbnail for Gallery-1.png]
Gallery-2.png
[Thumbnail for Gallery-2.png]
Gallery-3.png
[Thumbnail for Gallery-3.png]
 
Rancher
Posts: 4387
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it crashes the application.


What does "crashes" mean?  Normally crashing means the program throws an exception and stops running.  Is there anything on the logcat?

Does the program have all the required permissions?
 
Badar Ismail
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:

it crashes the application.


What does "crashes" mean?  Normally crashing means the program throws an exception and stops running.  Is there anything on the logcat?

Does the program have all the required permissions?



Thanks for responding, to avoid confusion thats why I put up a google drive link where I posted 2 small clips. Kindly have a look
And yes, all permissions were granted. By crashing I meant, it gives the message app not responding error message

https://drive.google.com/drive/folders/18oCeFkVEvi1xPv_O4DEI3EZz0TtVyZ36?usp=sharing

Also attached the LogCat messages when app crashes.

logCAT1.jpeg
[Thumbnail for logCAT1.jpeg]
logCAT2.jpeg
[Thumbnail for logCAT2.jpeg]
 
Norm Radder
Rancher
Posts: 4387
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please copy the text of the logcat's contents and paste it here.  The images are hard to read.
Text can not be copied from an image to be included in the response.  
Why is there a NPE shown in the trace?
 
Badar Ismail
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Please copy the text of the logcat's contents and paste it here.  The images are hard to read.
Text can not be copied from an image to be included in the response.  
Why is there a NPE shown in the trace?



Sorry sir. I didnt initally copy it because it wasnt allowing me to post long messages. Here it is! I have to look up what NPE is, this is actually my first time using android studio and making an app. So Im sorry Im unaware of what NPE is and why it is showing.

2021-07-17 17:01:38.730 18758-18758/com.example.textrecognition E/AndroidRuntime: FATAL EXCEPTION: main
   Process: com.example.textrecognition, PID: 18758
   java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=3, result=-1, data=Intent { dat=content://media/external/images/media/306689 flg=0x1 (has extras) }} to activity {com.example.textrecognition/com.example.textrecognition.MainActivity}: java.lang.NullPointerException: null reference
       at android.app.ActivityThread.deliverResults(ActivityThread.java:4610)
       at android.app.ActivityThread.handleSendResult(ActivityThread.java:4652)
       at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7050)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
    Caused by: java.lang.NullPointerException: null reference
       at com.google.android.gms.common.internal.Preconditions.checkNotNull(Unknown Source:2)
       at com.google.firebase.ml.vision.common.FirebaseVisionImage.<init>(com.google.firebase:firebase-ml-vision@@24.0.1:40)
       at com.google.firebase.ml.vision.common.FirebaseVisionImage.fromBitmap(com.google.firebase:firebase-ml-vision@@24.0.1:3)
       at com.example.textrecognition.MainActivity.onActivityResult(MainActivity.java:259)
       at android.app.Activity.dispatchActivityResult(Activity.java:7762)
       at android.app.ActivityThread.deliverResults(ActivityThread.java:4603)
       at android.app.ActivityThread.handleSendResult(ActivityThread.java:4652) 
       at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49) 
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948) 
       at android.os.Handler.dispatchMessage(Handler.java:106) 
       at android.os.Looper.loop(Looper.java:214) 
       at android.app.ActivityThread.main(ActivityThread.java:7050) 
       at java.lang.reflect.Method.invoke(Native Method) 
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
 
Badar Ismail
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Please copy the text of the logcat's contents and paste it here.  The images are hard to read.
Text can not be copied from an image to be included in the response.  
Why is there a NPE shown in the trace?



I hope these pictures are more clear
HD2.png
[Thumbnail for HD2.png]
HD.png
[Thumbnail for HD.png]
 
Norm Radder
Rancher
Posts: 4387
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


      at com.google.firebase.ml.vision.common.FirebaseVisionImage.fromBitmap(com.google.firebase:firebase-ml-vision@@24.0.1:3)  
      at com.example.textrecognition.MainActivity.onActivityResult(MainActivity.java:259)


What code is around line 259 in MainActivity?  Are there any variables with null values when that line is executed?

When I search the posted code for fromBitmap (name of method called at line 259) it is not found because the posts are images not text.
 
Badar Ismail
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:

      at com.example.textrecognition.MainActivity.onActivityResult(MainActivity.java:259)


What code is around line 259 in MainActivity?  Are there any variables with null values when that line is executed?

When I search the posted code for fromBitmap (name of method called at line 259) it is not found because the posts are images not text.



Yes so that entire code is the Google ML Kit. At Line 259. I am using Google's Firebase to extract and scan texts.

Sorry about that, I posted the whole code and indented it. It took me over 30 minutes, and while posting it, I got an error that its too long. Heres a google drive link, i got an idea to upload my sourcecode here. Please check it out. You will be able to search everything in the code. It is a word file

https://drive.google.com/drive/folders/1DhagBQDqEo0L_CplJW4g9ACf2SichJ3A?usp=sharing
 
Norm Radder
Rancher
Posts: 4387
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What code is around line 259 in MainActivity?
Sorry, I do not download stuff from other sites.
 
Badar Ismail
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:What code is around line 259 in MainActivity?
Sorry, I do not download stuff from other sites.



Why? It's Google Drive, an online cloud storage facility. Not a random website. You don't have to download it. You can just open it and view it, its just easier for you that way. How can I explain a 400+ line code here?

Line 259 has Google Firebase Code. Using ML Kit to scan and extract text.
 
Norm Radder
Rancher
Posts: 4387
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you look at line 259?  What variable had a null value when that line was executed?
 
Badar Ismail
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Did you look at line 259?  What variable had a null value when that line was executed?



Here is the code from Line 258 to 271

 
Norm Radder
Rancher
Posts: 4387
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What value does the bitmap variable contain when line 259 is executed?

Note:  posting lines following where the exception occurred often doesn't show what was done before the exception occurred.
 
Badar Ismail
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:What value does the bitmap variable contain when line 259 is executed?

Note:  posting lines following where the exception occurred often doesn't show what was done before the exception occurred.



It contains these

BITMAP-VALUE.png
[Thumbnail for BITMAP-VALUE.png]
 
Norm Radder
Rancher
Posts: 4387
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What value is in the variable: bitmap when the code on line 259 is executed?
 
Badar Ismail
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:What value is in the variable: bitmap when the code on line 259 is executed?



This is what you are talking about I think.



It is a pre-defined method, once the camera operation is over this function is automatically called to process the image to extract text from it.
The remaining code is in my above replies.
 
Norm Radder
Rancher
Posts: 4387
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am asking what the value is in the bitmap variable when line 259 is executed.  Add this line just before line 259 to print out the value so you can see it:
 
Badar Ismail
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:I am asking what the value is in the bitmap variable when line 259 is executed.  Add this line just before line 259 to print out the value so you can see it:



How to print it to console using systemoutprintln? I thought we can do it with Logcat but not sure how to print it. Sorry
 
Norm Radder
Rancher
Posts: 4387
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The print I suggested will be shown on the logcat.
I use printing to the logcat all the time to debug Android programs.
 
Badar Ismail
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:The print I suggested will be shown on the logcat.
I use printing to the logcat all the time to debug Android programs.


So I simple connect my device and run the program and open log cat, correct?
 
Norm Radder
Rancher
Posts: 4387
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I do not know how to look at the logcat on your device.
How did you do it before?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic