So, I have been following a YouTube tutorial for an android Weather application. The app seems to compile, however crashes whenever opened on the emulator. I'm not the most fluent programmer, however the code is understood. I can't figure out what's causing the issue though. The app is supposed to fetch weather data for the location of the hardcoded location in "MainActivity.java". The data is fetched from Yahoo! using an API.
Link for the project files: https://drive.google.com/drive/folders/0B2dQ9-JQjysVeXlqZENBZDExN0E?usp=sharing
Below is the error I get:
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mattbenson.cw_2_weather, PID: 2529
java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONObject.optInt(java.lang.String)' on a null object reference
at com.example.mattbenson.cw_2_weather.service.WeatherService$1.onPostExecute(WeatherService.java:81)
at com.example.mattbenson.cw_2_weather.service.WeatherService$1.onPostExecute(WeatherService.java:38)
at android.os.AsyncTask.finish(AsyncTask.java:667)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
at android.os.Handler.dispatchMessage(Handler.java:102)
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)
E/Surface: queueBuffer: error queuing buffer to SurfaceTexture, -19
E/EGL_emulation: tid 2570: swapBuffers(487): error 0x300d (EGL_BAD_SURFACE)
W/OpenGLRenderer: swapBuffers encountered EGL error 12301 on 0x76990bb1c580, halting rendering...
Application terminated.
(Sorry, I am new to this site!)
Any help is greatly appreciated.
As StackTrace says the error is at Class WeatherService at line 81 int count = queryResults.optInt("Count"); because it is returning NULL.
Try using method optInt with fallback value queryResults.optInt("Count", 0);
Related
im using kevalpatel2106's android hidden camera library.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.exampleapp, PID: 10608
java.lang.RuntimeException: takePicture failed
at android.hardware.Camera.native_takePicture(Native Method)
at android.hardware.Camera.takePicture(Camera.java:1865)
at android.hardware.Camera.takePicture(Camera.java:1806)
at com.androidhiddencamera.CameraPreview.takePictureInternal(CameraPreview.java:196)
at com.androidhiddencamera.HiddenCameraActivity.takePicture(HiddenCameraActivity.java:92)
at com.example.exampleapp.MainActivity.lambda$onCreate$3$MainActivity(MainActivity.java:152)
at com.example.exampleapp.MainActivity$$ExternalSyntheticLambda4.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7888)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:981)
when the application instance taking picture the first time it works fine, but in the second time it throws me this error.
I'm using LGE LM-K520 device android 11.
this is the code:
findViewById(R.id.pic).setOnClickListener((a) -> takePicture());
this is my config:
mCameraConfig = new CameraConfig()
.getBuilder(MainActivity.this)
.setCameraFacing(CameraFacing.REAR_FACING_CAMERA)
.setCameraResolution(CameraResolution.HIGH_RESOLUTION)
.setImageFormat(CameraImageFormat.FORMAT_JPEG)
.setImageRotation(CameraRotation.ROTATION_90)
.build();
Thank You!!!
I am making a chat app and want to implement a feature to get the online-offline and typing statuses for that in my adapter. I am trying to get the value from the database to display.
This is what I tried
FirebaseFirestore database = FirebaseFirestore.getInstance();
Log.d("conversationId",chatMessage.conversationId + "");
database.collection(Constants.KEY_COLLECTION_USERS)
.document(chatMessage.conversationId + "")
.addSnapshotListener((value, error) -> {
if (value.getString(Constants.KEY_AVAILABILITY).equals("0")){
binding.onlineIndicator.setVisibility(View.GONE);
binding.textRecentConversation.setText(chatMessage.message);
}else if (value.getString(Constants.KEY_AVAILABILITY).equals("1")){
binding.onlineIndicator.setVisibility(View.VISIBLE);
binding.textRecentConversation.setText(chatMessage.message);
}else if (value.getString(Constants.KEY_AVAILABILITY).equals("2")){
makeTypingText(binding, chatMessage.conversationName);
binding.onlineIndicator.setVisibility(View.VISIBLE);
}
});
And this is the error I got
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.chatverse.free, PID: 14452
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at com.chatverse.free.Adapters.RecentConversationsAdapter$ConversationViewHolder.lambda$setData$0$com-chatverse-free-Adapters-RecentConversationsAdapter$ConversationViewHolder(RecentConversationsAdapter.java:144)
at com.chatverse.free.Adapters.RecentConversationsAdapter$ConversationViewHolder$$ExternalSyntheticLambda3.onEvent(Unknown Source:6)
at com.google.firebase.firestore.DocumentReference.lambda$addSnapshotListenerInternal$2$com-google-firebase-firestore-DocumentReference(DocumentReference.java:504)
at com.google.firebase.firestore.DocumentReference$$ExternalSyntheticLambda2.onEvent(Unknown Source:6)
at com.google.firebase.firestore.core.AsyncEventListener.lambda$onEvent$0$com-google-firebase-firestore-core-AsyncEventListener(AsyncEventListener.java:42)
at com.google.firebase.firestore.core.AsyncEventListener$$ExternalSyntheticLambda0.run(Unknown Source:6)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
This is how I verified
First, in the logs, I check the value I printed for the receiver id. It's correct.
I also verified the keys, and everything is correct. I am not sure why such an error is occurring.
I got it.
I was using a static String, giving n error, but it worked when I tried using hard-coded values. Note that this gave me an emulator error but worked fine with an actual device! To make it work on an emulator, I had to try/catch for NullPointerExeption.
Thanks to #AlexMamo
I want to add Internet Connection Problem Dialog in my Async Task subclass. I tried many methods but the same error happened when my internet not connected.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.yasht.cricketapp, PID: 12793
java.lang.ClassCastException: java.lang.String cannot be cast to java.io.InputStream
at com.example.yasht.cricketapp.m_Rss.Downloader.onPostExecute(Downloader.java:66)
at android.os.AsyncTask.finish(AsyncTask.java:667)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
at android.os.Handler.dispatchMessage(Handler.java:102)
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)
Error Pointing On 66 line:
Please comment If you want any other information.
You are casting data into inputStream, if you want to create this object you should do something like : ByteArrayInputStream( data.getBytes() )
probably you should post your onExecute too to see what are you trying to do
We call from Ionic a custom Cordova plugin which uses the Camera2 API to capture a frame. On the second call of this plugin within Ionic (which follows subsequently) we get sometimes (like in one out of ten cases) the following error:
2019-01-14 18:08:16.471 31738-31738/io.ionic.starter E/Legacy-CameraDevice-JNI: getNativeWindow: Surface had no valid native window.
2019-01-14 18:08:16.472 31738-31738/io.ionic.starter E/Legacy-CameraDevice-JNI: LegacyCameraDevice_nativeDetectSurfaceDimens: Could not retrieve native window from surface.
2019-01-14 18:08:16.472 31738-31738/io.ionic.starter D/AndroidRuntime: Shutting down VM
2019-01-14 18:08:16.472 31738-31738/io.ionic.starter E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.ionic.starter, PID: 31738
java.lang.UnsupportedOperationException: Unknown error -22
at android.hardware.camera2.legacy.LegacyExceptionUtils.throwOnError(LegacyExceptionUtils.java:77)
at android.hardware.camera2.legacy.LegacyCameraDevice.getSurfaceSize(LegacyCameraDevice.java:583)
at android.hardware.camera2.utils.SurfaceUtils.getSurfaceSize(SurfaceUtils.java:68)
at android.hardware.camera2.params.OutputConfiguration.<init>(OutputConfiguration.java:237)
at android.hardware.camera2.params.OutputConfiguration.<init>(OutputConfiguration.java:101)
at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSession(CameraDeviceImpl.java:499)
at dev.capture.Camera2Scanner.createCameraPreviewSession(Camera2Scanner.java:675)
at dev.capture.Camera2Scanner.access$200(Camera2Scanner.java:47)
at dev.capture.Camera2Scanner$2.onOpened(Camera2Scanner.java:191)
at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:139)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
So I checked the Android JNI sources for this error, there it says that this error is thrown when getNativeWindow() returns null. But what extactly does this function do and what does this mean for our surface?
You've passed in a Surface to CameraDevice.createCaptureSession that's no longer valid; generally that's because whatever you got the Surface from has been either garbage collected, or because the UI element it draws to is no longer valid.
So if a SurfaceView is not valid to draw to any more, or an ImageReader has been released, etc, you can get this error. You need to sort out which Surface is invalid, and then figure out why its source is no longer in good shape.
I get the error Fatal Exception main whenever I run application .
the app uses opencv 2.4.10 it has worked on one device and it fails on my device I couldn't figure out why this is happening.
I don't know which part is code is causing this error :
09-13 10:55:30.039 19555-19555/org.blatnik.eyemon E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.blatnik.eyemon, PID: 19555
java.lang.RuntimeException: Unable to start service org.blatnik.eyemon.MainService#66d5693 with Intent { flg=0x10000000 cmp=org.blatnik.eyemon/.MainService }: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4079)
at android.app.ActivityThread.access$2400(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1897)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
at android.view.ViewRootImpl.setView(ViewRootImpl.java:853)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:337)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.app.Dialog.show(Dialog.java:350)
at **org.opencv.android.BaseLoaderCallback.onPackageInstall(BaseLoaderCallback.java:110)
at org.opencv.android.AsyncServiceHelper.InstallService(AsyncServiceHelper.java:117)
at org.opencv.android.AsyncServiceHelper.initOpenCV(AsyncServiceHelper.java:33)
at org.opencv.android.OpenCVLoader.initAsync(OpenCVLoader.java:85)
at org.blatnik.eyemon.MainService.onStartCommand(MainService.java:140)**
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4062)
at android.app.ActivityThread.access$2400(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1897)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
please any solution would be very thankful.
Apparently there is a task running which is using the context here with OpenCBLoader
(!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback))
The problem related with context i.e the context is not valid anymore
.Try passing getApplicationContext() instead of this
(!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, getApplicationContext(), mLoaderCallback))
Consider a case when AMK(android memory killer) kill your service due to memory shortage because service get to destroyed first before foreground activity and now your service is dead, plus the this context is not valid anymore hence Exception