Android webview not loading for localhost server - java

I have created a node.js web application and running it on port 3000. I wanted an android app for the same and created a webview based android app.
While testing I was trying to give the localhost ip, the static server IP but the webview app is not loading in all of them.
Output:
Android logcat:
09-25 20:54:12.508 7589-7589/? I/.cloudassigmen: Not late-enabling -Xcheck:jni (already on)
09-25 20:54:13.288 7589-7589/? W/.cloudassigmen: Unexpected CPU variant for X86 using defaults: x86
09-25 20:54:15.410 7589-7589/com.example.smitsanghvi.cloudassigment W/.cloudassigmen: JIT profile information will not be recorded: profile file does not exits.
09-25 20:54:15.431 7589-7589/com.example.smitsanghvi.cloudassigment I/chatty: uid=10085(com.example.smitsanghvi.cloudassigment) identical 10 lines
09-25 20:54:15.432 7589-7589/com.example.smitsanghvi.cloudassigment W/.cloudassigmen: JIT profile information will not be recorded: profile file does not exits.
09-25 20:54:15.740 7589-7589/com.example.smitsanghvi.cloudassigment I/InstantRun: starting instant run server: is main process
09-25 20:54:17.026 7589-7589/com.example.smitsanghvi.cloudassigment W/.cloudassigmen: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
09-25 20:54:17.033 7589-7589/com.example.smitsanghvi.cloudassigment W/.cloudassigmen: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
09-25 20:54:17.108 7589-7589/com.example.smitsanghvi.cloudassigment I/WebViewFactory: Loading com.android.chrome version 69.0.3497.100 (code 349710012)
09-25 20:54:17.599 7589-7589/com.example.smitsanghvi.cloudassigment I/cr_LibraryLoader: Time to load native libraries: 25 ms (timestamps 6319-6344)
09-25 20:54:17.744 7589-7589/com.example.smitsanghvi.cloudassigment I/chromium: [INFO:library_loader_hooks.cc(36)] Chromium logging enabled: level = 0, default verbosity = 0
09-25 20:54:17.745 7589-7589/com.example.smitsanghvi.cloudassigment I/cr_LibraryLoader: Expected native library version number "69.0.3497.100", actual native library version number "69.0.3497.100"
09-25 20:54:17.758 7589-7615/com.example.smitsanghvi.cloudassigment E/cr_VariationsUtils: Failed reading seed file "/data/user/0/com.example.smitsanghvi.cloudassigment/app_webview/variations_seed": /data/user/0/com.example.smitsanghvi.cloudassigment/app_webview/variations_seed (No such file or directory)
09-25 20:54:17.788 7589-7616/com.example.smitsanghvi.cloudassigment W/cr_ChildProcLH: Create a new ChildConnectionAllocator with package name = com.android.chrome, sandboxed = true
09-25 20:54:17.856 7589-7589/com.example.smitsanghvi.cloudassigment I/cr_BrowserStartup: Initializing chromium process, singleProcess=false
09-25 20:54:18.541 7589-7589/com.example.smitsanghvi.cloudassigment W/.cloudassigmen: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker;-><init>(Landroid/content/Context;I)V (light greylist, reflection)
Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker;->logEvent(Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;)V (light greylist, reflection)
09-25 20:54:18.542 7589-7589/com.example.smitsanghvi.cloudassigment W/.cloudassigmen: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionStarted(I)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(II)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(IILandroid/view/textclassifier/TextClassification;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(IILandroid/view/textclassifier/TextSelection;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionAction(III)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionAction(IIILandroid/view/textclassifier/TextClassification;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
09-25 20:54:18.720 7589-7638/com.example.smitsanghvi.cloudassigment W/cr_media: Requires BLUETOOTH permission
09-25 20:54:18.761 7589-7625/com.example.smitsanghvi.cloudassigment D/NetworkSecurityConfig: No Network Security Config specified, using platform default
09-25 20:54:18.806 7589-7589/com.example.smitsanghvi.cloudassigment D/OpenGLRenderer: Skia GL Pipeline
09-25 20:54:19.025 7589-7662/com.example.smitsanghvi.cloudassigment I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
09-25 20:54:19.027 7589-7662/com.example.smitsanghvi.cloudassigment I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
09-25 20:54:19.038 7589-7662/com.example.smitsanghvi.cloudassigment D/EGL_emulation: eglCreateContext: 0xcf803840: maj 3 min 0 rcv 3
09-25 20:54:19.039 7589-7662/com.example.smitsanghvi.cloudassigment D/EGL_emulation: eglMakeCurrent: 0xcf803840: ver 3 0 (tinfo 0xcf708f90)
09-25 20:54:19.262 7589-7667/com.example.smitsanghvi.cloudassigment I/OpenGLRenderer: Initialized EGL, version 1.4
09-25 20:54:19.262 7589-7667/com.example.smitsanghvi.cloudassigment D/OpenGLRenderer: Swap behavior 1
09-25 20:54:19.265 7589-7667/com.example.smitsanghvi.cloudassigment W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
09-25 20:54:19.266 7589-7667/com.example.smitsanghvi.cloudassigment D/OpenGLRenderer: Swap behavior 0
09-25 20:54:19.273 7589-7667/com.example.smitsanghvi.cloudassigment D/EGL_emulation: eglCreateContext: 0xcf8035a0: maj 3 min 0 rcv 3
09-25 20:54:19.292 7589-7667/com.example.smitsanghvi.cloudassigment D/EGL_emulation: eglMakeCurrent: 0xcf8035a0: ver 3 0 (tinfo 0xcf74e2b0)
09-25 20:54:19.638 7589-7667/com.example.smitsanghvi.cloudassigment D/EGL_emulation: eglMakeCurrent: 0xcf8035a0: ver 3 0 (tinfo 0xcf74e2b0)
09-25 20:54:19.896 7589-7662/com.example.smitsanghvi.cloudassigment W/VideoCapabilities: Unrecognized profile 4 for video/hevc
09-25 20:54:20.048 7589-7662/com.example.smitsanghvi.cloudassigment I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
09-25 20:54:20.107 7589-7667/com.example.smitsanghvi.cloudassigment I/OpenGLRenderer: Davey! duration=900ms; Flags=0, IntendedVsync=2307946960898, Vsync=2308346960882, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=2308351487351, AnimationStart=2308351545351, PerformTraversalsStart=2308351596351, DrawStart=2308377901351, SyncQueued=2308383974351, SyncStart=2308389276351, IssueDrawCommandsStart=2308391431351, SwapBuffers=2308827224351, FrameCompleted=2308853055351, DequeueBufferDuration=328000, QueueBufferDuration=1955000,
09-25 20:54:20.107 7589-7662/com.example.smitsanghvi.cloudassigment W/cr_MediaCodecUtil: HW encoder for video/avc is not available on this device.
09-25 20:54:20.291 7589-7613/com.example.smitsanghvi.cloudassigment W/cr_CrashFileManager: /data/user/0/com.example.smitsanghvi.cloudassigment/cache/WebView/Crash Reports does not exist or is not a directory
09-25 20:54:23.405 7589-7662/com.example.smitsanghvi.cloudassigment D/EGL_emulation: eglCreateContext: 0xca251560: maj 3 min 0 rcv 3
09-25 20:54:23.406 7589-7662/com.example.smitsanghvi.cloudassigment D/EGL_emulation: eglMakeCurrent: 0xca251560: ver 3 0 (tinfo 0xcf708f90)
09-25 20:54:31.146 7589-7589/com.example.smitsanghvi.cloudassigment I/chromium: [INFO:CONSOLE(32048)] source: http://10.0.2.2:3000/static/js/bundle.js (32048)
09-25 20:54:31.679 7589-7589/com.example.smitsanghvi.cloudassigment I/chromium: [INFO:CONSOLE(43724)] "Uncaught TypeError: Cannot read property 'apply' of undefined", source: http://10.0.2.2:3000/static/js/bundle.js (43724)
I tried these IPs:
localhost:3000
http://127.0.0.1:3000/
http://10.0.2.2:3000
All of them are working from my browser.
Mainactivity.java
package com.example.smitsanghvi.cloudassigment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView webview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new WebViewClient());
webview.loadUrl("127.0.0.1:3000");
WebSettings webSettings=webview.getSettings();
webSettings.setJavaScriptEnabled(true);
}
#Override
public void onBackPressed() {
if(webview.canGoBack())
{
webview.goBack();
}
else {
super.onBackPressed();
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.smitsanghvi.cloudassigment">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

If you're using a physical device to run, then,
make sure your website is running at 192.168.x.xxx:port
set the full url in your activity, such as,
webview.loadUrl("http://192.168.1.107:3000/");
add
android:usesCleartextTraffic="true"
in AndroidManifest.xml to fix 'cleartext not permitted' error caused for not using https
For emulator use 10.0.2.2 as stated in the previous answer and follow the 3rd step

Use this
webview.loadUrl("http://10.0.2.2:3000");
Instead of
webview.loadUrl("127.0.0.1:3000");

Related

Permission denied for Android Studio

I have a permission denied problem when I run the app in my android studio. Before that, I need to declare that my group mates can run the code and pop out the data but me, we all use the same code and version but I use a mac that they use the win system.
Below is the logcat info:
Late-enabling -Xcheck:jni
E/ample.inclass0: Unknown bits set in runtime_flags: 0x8000
W/ample.inclass0: Unexpected CPU variant for X86 using defaults: x86
D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
W/RenderThread: type=1400 audit(0.0:660): avc: denied { write } for name="property_service" dev="tmpfs" ino=857 scontext=u:r:untrusted_app:s0:c151,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0
W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
W/ample.inclass0: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/ample.inclass0: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
W/System.err: java.net.SocketException: socket failed: EPERM (Operation not permitted)
W/System.err: at java.net.Socket.createImpl(Socket.java:492)
W/System.err: at java.net.Socket.getImpl(Socket.java:552)
W/System.err: at java.net.Socket.setSoTimeout(Socket.java:1180)
W/System.err: at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:293)
W/System.err: at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:207)
W/System.err: at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
W/System.err: at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
W/System.err: at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
W/System.err: at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
W/System.err: at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
W/System.err: at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err: at java.lang.Thread.run(Thread.java:919)
D/HostConnection: HostConnection::get() New Host Connection established 0xdb7e2040, tid 5252
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_sync_buffer_data GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
D/EGL_emulation: eglCreateContext: 0xf1f7e5c0: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0xf1f7e5c0: ver 3 0 (tinfo 0xe6d24dd0)
W/Gralloc3: mapper 3.x is not supported
D/HostConnection: createUnique: call
D/HostConnection: HostConnection::get() New Host Connection established 0xdb7e3800, tid 5252
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_sync_buffer_data GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0
D/eglCodecCommon: allocate: Ask for block of size 0x1000
D/eglCodecCommon: allocate: ioctl allocate returned offset 0x3ff807000 size 0x2000
D/EGL_emulation: eglMakeCurrent: 0xf1f7e5c0: ver 3 0 (tinfo 0xe6d24dd0)
D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
Below is the AndroidMainfest file:
For toolsLtargetApi="31" I tried to delete and run nothing changed
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.inclass07">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.InClass07"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Could anyone give me some suggestions to solve the issue? Any help is appreciated.
I am not sure if this will work for everyone, but I solved my problem by changing the Emulator.
Previously, I used the Nexus 5X Q(API29), but now I switched to the Nexus 5X API33 and doing so solved my problem.
I also tried others with API33 and they work just fine.

Chronometer crashes emulator

new to java and was following a tutorial on building a chronometer app from scratch.
The app compiles but when pressing start or stop in emulator the app crashes.
Start crashes app without notification,
Pause crashes app with notification about crash and fill a report suggestion,
stop doesnt crash but does nothing.
I have searched multiply sites about it and dont seem to find a problem in it.
main activity java
package com.example.dayswithout;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.Chronometer;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private Chronometer chronometer;
private long pauseOffset;
private Boolean running;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chronometer=findViewById(R.id.chronometer);
chronometer.setFormat("Time: %s");
chronometer.setBase(SystemClock.elapsedRealtime());
chronometer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
#Override
public void onChronometerTick(Chronometer chronometer) {
if ((SystemClock.elapsedRealtime() - chronometer.getBase()) >= 10000) {
chronometer.setBase(SystemClock.elapsedRealtime());
Toast.makeText(MainActivity.this, "Bing!", Toast.LENGTH_SHORT).show();
}
}
});
}
public void startChronometer(View v){
if(!running) {
chronometer.setBase(SystemClock.elapsedRealtime()-pauseOffset);
chronometer.start();
running = true;
}
}
public void pauseChronometer(View v){
if(running) {
chronometer.stop();
pauseOffset=SystemClock.elapsedRealtime()-chronometer.getBase();
running = false;
}
}
public void resetChronometer(View v){
chronometer.setBase(SystemClock.elapsedRealtime());
pauseOffset=0;
}
}
activity main xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<Chronometer
android:id="#+id/chronometer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="startChronometer"
android:text="Start"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pause"
android:onClick="pauseChronometer"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="reset"
android:onClick="resetChronometer"/>
</LinearLayout>
Log
02/22 14:19:49: Launching 'app' on No Devices.
Install successfully finished in 1 s 718 ms.
$ adb shell am start -n "com.example.dayswithout/com.example.dayswithout.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 6915 on device 'emulator-5554'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/ple.dayswithou: Not late-enabling -Xcheck:jni (already on)
I/ple.dayswithou: Unquickening 12 vdex files!
W/ple.dayswithou: Unexpected CPU variant for X86 using defaults: x86
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
W/ple.dayswithou: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/ple.dayswithou: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
D/HostConnection: HostConnection::get() New Host Connection established 0xebb41ac0, tid 7013
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/EGL_emulation: eglCreateContext: 0xebb41a50: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0xebb41a50: ver 2 0 (tinfo 0xebe96950) (first time)
I/Gralloc4: mapper 4.x is not supported
D/HostConnection: createUnique: call
HostConnection::get() New Host Connection established 0xebb41eb0, tid 7013
D/goldfish-address-space: allocate: Ask for block of size 0x100
allocate: ioctl allocate returned offset 0x3fbda9000 size 0x2000
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2
I/OpenGLRenderer: Davey! duration=1037ms; Flags=1, IntendedVsync=748790555628, Vsync=748807222294, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=748815462000, AnimationStart=748815491400, PerformTraversalsStart=748816913000, DrawStart=749730608800, SyncQueued=749763725800, SyncStart=749765306700, IssueDrawCommandsStart=749765382800, SwapBuffers=749827691200, FrameCompleted=749829712000, DequeueBufferDuration=138600, QueueBufferDuration=791000, GpuCompleted=-2920196950870201425,
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dayswithout, PID: 6915
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:414)
at android.view.View.performClick(View.java:7448)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View.performClickInternal(View.java:7425)
at android.view.View.access$3600(View.java:810)
at android.view.View$PerformClick.run(View.java:28305)
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)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409)
at android.view.View.performClick(View.java:7448) 
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119) 
at android.view.View.performClickInternal(View.java:7425) 
at android.view.View.access$3600(View.java:810) 
at android.view.View$PerformClick.run(View.java:28305) 
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) 
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
at com.example.dayswithout.MainActivity.startChronometer(MainActivity.java:35)
at java.lang.reflect.Method.invoke(Native Method) 
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409) 
at android.view.View.performClick(View.java:7448) 
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119) 
at android.view.View.performClickInternal(View.java:7425) 
at android.view.View.access$3600(View.java:810) 
at android.view.View$PerformClick.run(View.java:28305) 
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) 
I/Process: Sending signal. PID: 6915 SIG: 9
Here you have the problem:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
at com.example.dayswithout.MainActivity.startChronometer(MainActivity.java:35)
Which refers to that the running variable is not initialised:
public void startChronometer(View v){
if(!running) {
I would recommend changing it from a wrapped Boolean that is an object and not set, so value of it is null. to a primitive boolean in the declaration:
private Boolean running;
->
private boolean running = false;
And maybe set it to false for clairity (optional because false is the default value).
The error indicates that your object isn't instantiated:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
Boolean is an Object type, a reference type, requiring instantiation. In your case private Boolean running; is declared but it is never instantiated, resulting in the above NullPointerException
Instead, change the type from Boolean to the primitve boolean. You don't have to initialise it since it will use the default value of false. However, for readability it may be wise to initiliase it
private boolean running = false;

Retrieve Data from multiple documents from Firestore Database

Unable to fetch a value from the Firestore database. Trying to retrieve the value of the mobile number as and when the value of flat and block matches the entry in the database. Below is the code I am using. I have also attached the issues that are registered in LogCat file. Please check and help.
public class Test extends AppCompatActivity {
Button btn;
private FirebaseFirestore firestore;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
firestore = FirebaseFirestore.getInstance();
btn = (Button) findViewById(R.id.button3);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getmobile();
//makecall();
}
});
}
private void makecall(){
Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);
intent.setData(Uri.parse("tel:9890910640"));
startActivity(intent);
}
private void getmobile() {
firestore.collection("users").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
#Override
public void onSuccess(QuerySnapshot documentSnapshots) {
String a = "101";
String b = "F1A";
for(DocumentSnapshot document: documentSnapshots){
if(document.getString("flat")==a&&document.getString("block")==b){
String mobilefromdatabase = document.get("mobile").toString();
Toast.makeText(Test.this, "mobile" + mobilefromdatabase, Toast.LENGTH_LONG).show();
break;
}
}
}
});
}
}
Logcat Details
05-05 03:59:26.721 8805-8805/? E/libprocessgroup: failed to make and chown /acct/uid_10058: Read-only file system
05-05 03:59:26.721 8805-8805/? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
05-05 03:59:26.722 8805-8805/? I/art: Not late-enabling -Xcheck:jni (already on)
05-05 03:59:26.770 8805-8805/com.example.myrwaapp I/MultiDex: VM with version 2.1.0 has multidex support
05-05 03:59:26.770 8805-8805/com.example.myrwaapp I/MultiDex: Installing application
05-05 03:59:26.770 8805-8805/com.example.myrwaapp I/MultiDex: VM has multidex support, MultiDex support library is disabled.
05-05 03:59:26.842 8805-8805/com.example.myrwaapp V/FA: Registered activity lifecycle callback
05-05 03:59:26.857 8805-8831/com.example.myrwaapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
05-05 03:59:26.861 8805-8805/com.example.myrwaapp I/FirebaseInitProvider: FirebaseApp initialization successful
05-05 03:59:26.907 8805-8834/com.example.myrwaapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
05-05 03:59:26.925 8805-8834/com.example.myrwaapp I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
05-05 03:59:26.986 8805-8805/com.example.myrwaapp W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
05-05 03:59:27.010 8805-8805/com.example.myrwaapp V/FA: onActivityCreated
05-05 03:59:27.047 8805-8805/com.example.myrwaapp I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
05-05 03:59:27.047 8805-8805/com.example.myrwaapp I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
05-05 03:59:27.048 8805-8830/com.example.myrwaapp V/FA: App measurement collection enabled
05-05 03:59:27.049 8805-8830/com.example.myrwaapp V/FA: App measurement enabled for app package, google app id: com.example.myrwaapp, 1:649640616763:android:9025242f82dd4767798d1e
05-05 03:59:27.052 8805-8830/com.example.myrwaapp I/FA: App measurement initialized, version: 21028
05-05 03:59:27.052 8805-8830/com.example.myrwaapp I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
05-05 03:59:27.052 8805-8830/com.example.myrwaapp I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app com.example.myrwaapp
05-05 03:59:27.052 8805-8830/com.example.myrwaapp D/FA: Debug-level message logging enabled
05-05 03:59:27.077 8805-8830/com.example.myrwaapp V/FA: Connecting to remote service
05-05 03:59:27.089 8805-8830/com.example.myrwaapp V/FA: Connection attempt already in progress
05-05 03:59:27.143 8805-8830/com.example.myrwaapp V/FA: Activity resumed, time: 8622127
05-05 03:59:27.145 8805-8830/com.example.myrwaapp I/FA: Tag Manager is not found and thus will not be used
05-05 03:59:27.151 8805-8838/com.example.myrwaapp D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
05-05 03:59:27.154 8805-8805/com.example.myrwaapp D/Atlas: Validating map...
05-05 03:59:27.159 8805-8830/com.example.myrwaapp V/FA: Connection attempt already in progress
05-05 03:59:27.159 8805-8830/com.example.myrwaapp V/FA: Connection attempt already in progress
05-05 03:59:27.188 8805-8838/com.example.myrwaapp I/OpenGLRenderer: Initialized EGL, version 1.4
05-05 03:59:27.188 8805-8838/com.example.myrwaapp W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
05-05 03:59:27.215 8805-8838/com.example.myrwaapp D/EGL_emulation: eglCreateContext: 0xa2003100: maj 2 min 0 rcv 2
05-05 03:59:27.240 8805-8838/com.example.myrwaapp D/EGL_emulation: eglMakeCurrent: 0xa2003100: ver 2 0 (tinfo 0xb4233e90)
05-05 03:59:27.243 8805-8838/com.example.myrwaapp D/OpenGLRenderer: Enabling debug mode 0
05-05 03:59:27.294 8805-8838/com.example.myrwaapp D/EGL_emulation: eglMakeCurrent: 0xa2003100: ver 2 0 (tinfo 0xb4233e90)
05-05 03:59:27.738 8805-8830/com.example.myrwaapp D/FA: Connected to remote service
05-05 03:59:27.738 8805-8830/com.example.myrwaapp V/FA: Processing queued up service tasks: 4
05-05 03:59:32.795 8805-8830/com.example.myrwaapp V/FA: Inactivity, disconnecting from the service
05-05 03:59:38.884 8805-8830/com.example.myrwaapp V/FA: Recording user engagement, ms: 11740
05-05 03:59:38.886 8805-8830/com.example.myrwaapp V/FA: Connecting to remote service
05-05 03:59:38.892 8805-8830/com.example.myrwaapp V/FA: Activity paused, time: 8633867
05-05 03:59:38.894 8805-8805/com.example.myrwaapp V/FA: onActivityCreated
05-05 03:59:38.913 8805-8830/com.example.myrwaapp V/FA: Connection attempt already in progress
05-05 03:59:38.913 8805-8830/com.example.myrwaapp V/FA: Activity resumed, time: 8633895
05-05 03:59:38.926 8805-8830/com.example.myrwaapp V/FA: Connection attempt already in progress
05-05 03:59:38.926 8805-8830/com.example.myrwaapp V/FA: Connection attempt already in progress
05-05 03:59:38.993 8805-8838/com.example.myrwaapp D/EGL_emulation: eglMakeCurrent: 0xa2003100: ver 2 0 (tinfo 0xb4233e90)
05-05 03:59:39.034 8805-8838/com.example.myrwaapp D/EGL_emulation: eglMakeCurrent: 0xa2003100: ver 2 0 (tinfo 0xb4233e90)
05-05 03:59:39.051 8805-8838/com.example.myrwaapp D/EGL_emulation: eglMakeCurrent: 0xa2003100: ver 2 0 (tinfo 0xb4233e90)
05-05 03:59:39.177 8805-8838/com.example.myrwaapp D/EGL_emulation: eglMakeCurrent: 0xa2003100: ver 2 0 (tinfo 0xb4233e90)
05-05 03:59:39.222 8805-8830/com.example.myrwaapp D/FA: Connected to remote service
05-05 03:59:39.222 8805-8830/com.example.myrwaapp V/FA: Processing queued up service tasks: 4
05-05 03:59:39.224 8805-8838/com.example.myrwaapp D/EGL_emulation: eglMakeCurrent: 0xa2003100: ver 2 0 (tinfo 0xb4233e90)
05-05 03:59:39.335 8805-8838/com.example.myrwaapp D/EGL_emulation: eglMakeCurrent: 0xa2003100: ver 2 0 (tinfo 0xb4233e90)
05-05 03:59:44.247 8805-8830/com.example.myrwaapp V/FA: Inactivity, disconnecting from the service
05-05 03:59:48.704 8805-8838/com.example.myrwaapp D/EGL_emulation: eglMakeCurrent: 0xa2003100: ver 2 0 (tinfo 0xb4233e90)
05-05 03:59:48.871 8805-8849/com.example.myrwaapp W/DynamiteModule: Local module descriptor class for providerinstaller not found.
05-05 03:59:48.877 8805-8849/com.example.myrwaapp I/DynamiteModule: Considering local module providerinstaller:0 and remote module providerinstaller:0
05-05 03:59:48.877 8805-8849/com.example.myrwaapp W/ProviderInstaller: Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
05-05 03:59:48.881 8805-8849/com.example.myrwaapp W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
05-05 03:59:48.881 8805-8849/com.example.myrwaapp W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
05-05 03:59:48.942 8805-8849/com.example.myrwaapp W/linker: libconscrypt_gmscore_jni.so: unused DT entry: type 0x6ffffffe arg 0x13dc
05-05 03:59:48.942 8805-8849/com.example.myrwaapp W/linker: libconscrypt_gmscore_jni.so: unused DT entry: type 0x6fffffff arg 0x2
05-05 03:59:48.948 8805-8849/com.example.myrwaapp V/NativeCrypto: Registering com/google/android/gms/org/conscrypt/NativeCrypto's 284 native methods...
05-05 03:59:48.963 8805-8820/com.example.myrwaapp I/art: Background sticky concurrent mark sweep GC freed 976(49KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 8MB/8MB, paused 5.861ms total 31.265ms
05-05 03:59:48.992 8805-8849/com.example.myrwaapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.org.conscrypt.Java7ExtendedSSLSession>
05-05 03:59:48.992 8805-8849/com.example.myrwaapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.org.conscrypt.Java7ExtendedSSLSession>
05-05 03:59:48.992 8805-8849/com.example.myrwaapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.org.conscrypt.Java8ExtendedSSLSession>
05-05 03:59:48.992 8805-8849/com.example.myrwaapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.org.conscrypt.Java8ExtendedSSLSession>
05-05 03:59:49.002 8805-8849/com.example.myrwaapp I/ProviderInstaller: Installed default security provider GmsCore_OpenSSL
First of all, String comparison in Java, should not be performed using == operator, as it will always compare the address of the objects from the memory and not the actual values. String comparison should be done using equals() method.
Moreover, if you need an AND operation, you should not get all documents that exist within the users collection and make the comparison on the client. For that, you should use a query that looks exactly like this:
String a = "101";
String b = "F1A";
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
CollectionReference usersRef = rootRef.collection("users");
Query query = usersRef.whereEqualTo("flat", a).whereEqualTo("block", b);
query.get().addOnSuccessListener(/* ... */);
In this way, you are going to get only the documents where the flat property holds the value of 101 AND the value of block holds F1A. As I think that only one apartment has that constraint, you'll be billed with only one read operation.

MediaPlayer no content provider error: W/MediaPlayer: Couldn't open https://youtu.be/oEgpGv2CF1U: java.io.FileNotFoundException: No content provider:

Here is the full log:
03-20 22:49:26.953 4986-4986/? I/art: Not late-enabling -Xcheck:jni (already on)
03-20 22:49:26.955 4986-4986/? W/art: Unexpected CPU variant for X86 using defaults: x86
03-20 22:49:27.232 4986-4986/com.example.alphie.androidvideostream W/System: ClassLoader referenced unknown path: /data/app/com.example.alphie.androidvideostream-1/lib/x86
03-20 22:49:27.250 4986-4986/com.example.alphie.androidvideostream I/InstantRun: starting instant run server: is main process
03-20 22:49:27.535 4986-4986/com.example.alphie.androidvideostream W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
03-20 22:49:27.737 4986-5002/com.example.alphie.androidvideostream I/OpenGLRenderer: Initialized EGL, version 1.4
03-20 22:49:27.737 4986-5002/com.example.alphie.androidvideostream D/OpenGLRenderer: Swap behavior 1
03-20 22:49:27.738 4986-5002/com.example.alphie.androidvideostream W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
03-20 22:49:27.738 4986-5002/com.example.alphie.androidvideostream D/OpenGLRenderer: Swap behavior 0
03-20 22:49:27.741 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglCreateContext: 0x9f6316c0: maj 3 min 0 rcv 3
03-20 22:49:27.743 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
03-20 22:49:27.784 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
03-20 22:58:08.625 4986-4986/com.example.alphie.androidvideostream W/MediaPlayer: Couldn't open https://youtu.be/oEgpGv2CF1U: java.io.FileNotFoundException: No content provider: https://youtu.be/oEgpGv2CF1U
03-20 22:58:08.635 4986-4998/com.example.alphie.androidvideostream D/NetworkSecurityConfig: No Network Security Config specified, using platform default
03-20 22:58:08.666 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
03-20 22:58:09.980 4986-5049/com.example.alphie.androidvideostream E/MediaPlayer: error (1, -2147483648)
03-20 22:58:09.980 4986-4986/com.example.alphie.androidvideostream E/MediaPlayer: Error (1,-2147483648)
03-20 22:58:09.980 4986-4986/com.example.alphie.androidvideostream D/VideoView: Error: 1,-2147483648
03-20 22:58:10.069 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
03-20 22:58:10.092 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
03-20 22:58:10.131 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
03-20 22:58:10.141 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
03-20 22:58:11.625 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
03-20 22:58:11.647 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
03-20 22:58:11.661 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
03-20 22:58:11.669 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
03-20 22:58:11.675 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
03-20 22:58:11.745 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
03-20 22:58:11.759 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
03-20 22:58:11.927 4986-5002/com.example.alphie.androidvideostream D/EGL_emulation: eglMakeCurrent: 0x9f6316c0: ver 3 0 (tinfo 0x9d6fe6a0)
"can't play video" error displays after hitting play button
As you can see, I have internet with the uses permission. heres my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.alphie.androidvideostream">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
and here is my java for my MainActivity:
package com.example.alphie.androidvideostream;
import android.app.ProgressDialog;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity implements
View.OnClickListener {
ProgressDialog mDialog;
VideoView videoView;
ImageButton btnPlayPause;
String videoURL = "https://youtu.be/oEgpGv2CF1U";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView= (VideoView)findViewById(R.id.videoView);
btnPlayPause = (ImageButton)findViewById(R.id.btn_play_pause);
btnPlayPause.setOnClickListener(this);
}
#Override
public void onClick(View v) {
mDialog = new ProgressDialog(MainActivity.this);
mDialog.setMessage("Please wait...");
mDialog.setCanceledOnTouchOutside(false);
mDialog.show();
try
{
if(!videoView.isPlaying()) {
Uri uri = Uri.parse(videoURL);
videoView.setVideoURI(uri);
videoView.setOnCompletionListener(new
MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
btnPlayPause.setImageResource(R.drawable.ic_play);
}
});
}
else
{
videoView.pause();
btnPlayPause.setImageResource(R.drawable.ic_play);
}
}
catch (Exception ex )
{
}
videoView.requestFocus();
videoView.setOnPreparedListener(new
MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mDialog.dismiss();
mp.setLooping(true);
videoView.start();
btnPlayPause.setImageResource(R.drawable.ic_pause);
}
});
}
}
As you can see, I have parsed the url and am using uri so that way i can get a remote video. any ideas? thanks
https://youtu.be/oEgpGv2CF1U points to a website, not a video stream. An example of a video stream URI would be
rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov.
It used to be possible to get YouTube stream URIs using the YouTube API, but it was changed in 2015. I suggest you launch the video in the YouTube app, as detailed here.

Android app keeps crashing on emulator and device [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 3 years ago.
I am executing a very basic task of opening another activity using a button. The code seems to be error-free but the app crashes without even showing the main activity. This happens on both the emulator as well as my device.
When the app has no function, i.e. when the app has just buttons which do nothing, the app works fine. But if I try to make them do anything(intent to open another activity, or to play with their visibility) the app crashes.
The logcat is as follows:
11-12 13:55:56.627 2962-2962/? D/AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
11-12 13:55:56.628 2962-2962/? D/AndroidRuntime: CheckJNI is ON
11-12 13:55:56.672 2962-2962/? D/ICU: No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
11-12 13:55:56.754 2962-2962/? E/memtrack: Couldn't load memtrack module (No such file or directory)
11-12 13:55:56.754 2962-2962/? E/android.os.Debug: failed to load memtrack module: -2
11-12 13:55:56.755 2962-2962/? I/Radio-JNI: register_android_hardware_Radio DONE
11-12 13:55:56.761 2962-2962/? D/AndroidRuntime: Calling main entry com.android.commands.pm.Pm
11-12 13:55:56.772 2962-2962/? I/art: System.exit called, status: 0
11-12 13:55:56.772 2962-2962/? I/AndroidRuntime: VM exiting with result code 0.
11-12 13:55:57.068 2977-2977/? D/AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
11-12 13:55:57.069 2977-2977/? D/AndroidRuntime: CheckJNI is ON
11-12 13:55:57.129 2977-2977/? D/ICU: No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
11-12 13:55:57.199 2977-2977/? E/memtrack: Couldn't load memtrack module (No such file or directory)
11-12 13:55:57.199 2977-2977/? E/android.os.Debug: failed to load memtrack module: -2
11-12 13:55:57.200 2977-2977/? I/Radio-JNI: register_android_hardware_Radio DONE
11-12 13:55:57.205 2977-2977/? D/AndroidRuntime: Calling main entry com.android.commands.pm.Pm
11-12 13:55:57.216 2977-2977/? I/art: System.exit called, status: 0
11-12 13:55:57.220 2977-2977/? I/AndroidRuntime: VM exiting with result code 0.
11-12 13:55:59.484 2987-2987/? D/AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
11-12 13:55:59.487 2987-2987/? D/AndroidRuntime: CheckJNI is ON
11-12 13:55:59.522 2987-2987/? D/ICU: No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
11-12 13:55:59.602 2987-2987/? E/memtrack: Couldn't load memtrack module (No such file or directory)
11-12 13:55:59.602 2987-2987/? E/android.os.Debug: failed to load memtrack module: -2
11-12 13:55:59.603 2987-2987/? I/Radio-JNI: register_android_hardware_Radio DONE
11-12 13:55:59.615 2987-2987/? D/AndroidRuntime: Calling main entry com.android.commands.wm.Wm
11-12 13:55:59.643 2987-2987/? D/AndroidRuntime: Shutting down VM
11-12 13:56:01.407 2999-2999/? D/AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
11-12 13:56:01.408 2999-2999/? D/AndroidRuntime: CheckJNI is ON
11-12 13:56:01.465 2999-2999/? D/ICU: No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
11-12 13:56:01.542 2999-2999/? E/memtrack: Couldn't load memtrack module (No such file or directory)
11-12 13:56:01.542 2999-2999/? E/android.os.Debug: failed to load memtrack module: -2
11-12 13:56:01.543 2999-2999/? I/Radio-JNI: register_android_hardware_Radio DONE
11-12 13:56:01.553 2999-2999/? D/AndroidRuntime: Calling main entry com.android.commands.am.Am
--------- beginning of system
11-12 13:56:01.562 1585-1920/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.dell.crash/.MainActivity} from uid 0 on display 0
11-12 13:56:01.579 2147-2341/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_close com.google.android.apps.gsa.speech.audio.u#20f33e2
11-12 13:56:01.605 3007-3007/? I/art: Not late-enabling -Xcheck:jni (already on)
11-12 13:56:01.606 2147-2347/com.google.android.googlequicksearchbox:search I/HotwordRecognitionRnr: Stopping hotword detection.
11-12 13:56:01.606 2147-2699/com.google.android.googlequicksearchbox:search I/HotwordRecognitionRnr: Hotword detection finished
11-12 13:56:01.610 1585-1598/system_process I/ActivityManager: Start proc 3007:com.example.dell.crash/u0a64 for activity com.example.dell.crash/.MainActivity
11-12 13:56:01.604 2999-2999/? D/AndroidRuntime: Shutting down VM
[ 11-12 13:56:01.697 1585: 1608 D/ ]
HostConnection::get() New Host Connection established 0x7f8480e69e40, tid 1608
11-12 13:56:01.728 3007-3007/com.example.dell.crash W/System: ClassLoader referenced unknown path: /data/app/com.example.dell.crash-1/lib/x86_64
11-12 13:56:01.729 3007-3007/com.example.dell.crash I/InstantRun: Instant Run Runtime started. Android package is com.example.dell.crash, real application class is null.
11-12 13:56:02.906 1891-2316/com.google.android.googlequicksearchbox E/Surface: getSlotFromBufferLocked: unknown buffer: 0xe9e5e990
11-12 13:56:03.510 3007-3007/com.example.dell.crash W/System: ClassLoader referenced unknown path: /data/app/com.example.dell.crash-1/lib/x86_64
11-12 13:56:03.707 3007-3007/com.example.dell.crash D/AndroidRuntime: Shutting down VM
--------- beginning of crash
11-12 13:56:03.707 3007-3007/com.example.dell.crash E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dell.crash, PID: 3007
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.dell.crash/com.example.dell.crash.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:116)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:50)
at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:29)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:199)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:181)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:521)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
at com.example.dell.crash.MainActivity.<init>(MainActivity.java:10)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
11-12 13:56:03.708 1585-2055/system_process W/ActivityManager: Force finishing activity com.example.dell.crash/.MainActivity
11-12 13:56:04.016 1585-2055/system_process I/WindowManager: Screenshot max retries 4 of Token{9795bf6 ActivityRecord{989c091 u0 com.example.dell.crash/.MainActivity t51 f}} appWin=Window{a3bf3ce u0 Starting com.example.dell.crash} drawState=4
11-12 13:56:04.116 1585-2485/system_process I/OpenGLRenderer: Initialized EGL, version 1.4
11-12 13:56:04.518 1585-1601/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{989c091 u0 com.example.dell.crash/.MainActivity t51 f}
11-12 13:56:04.550 2328-2336/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/networkstatistics.sqlite' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
11-12 13:56:04.550 2328-2336/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
11-12 13:56:04.551 2328-2336/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/help_responses.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
11-12 13:56:04.572 2328-2336/com.google.android.gms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
11-12 13:56:04.860 1585-1602/system_process I/Choreographer: Skipped 35 frames! The application may be doing too much work on its main thread.
11-12 13:56:04.925 2147-3076/com.google.android.googlequicksearchbox:search I/HotwordRecognitionRnr: Starting hotword detection.
11-12 13:56:04.943 2147-3078/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_starting com.google.android.apps.gsa.speech.audio.u#76753fd
11-12 13:56:04.955 1585-1599/system_process I/ActivityManager: Killing 2527:com.android.settings/1000 (adj 15): empty #17
11-12 13:56:04.965 1202-2042/? E/audio_hw_generic: Error opening input stream format 1, channel_mask 0010, sample_rate 16000
11-12 13:56:04.969 1202-3080/? I/AudioFlinger: AudioFlinger's thread 0xf3b80000 ready to run
11-12 13:56:04.988 2147-3078/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_started com.google.android.apps.gsa.speech.audio.u#76753fd
11-12 13:56:04.991 2147-2341/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_close com.google.android.apps.gsa.speech.audio.u#76753fd
11-12 13:56:04.992 2147-3078/com.google.android.googlequicksearchbox:search E/AudioRecord-JNI: Error -4 during AudioRecord native read
11-12 13:56:05.009 2147-2347/com.google.android.googlequicksearchbox:search I/HotwordRecognitionRnr: Stopping hotword detection.
11-12 13:56:05.010 2147-3076/com.google.android.googlequicksearchbox:search I/HotwordRecognitionRnr: Hotword detection finished
11-12 13:56:05.140 1585-1599/system_process I/ActivityManager: Killing 2649:com.android.dialer/u0a4 (adj 15): empty #17
11-12 13:56:05.395 1891-2316/com.google.android.googlequicksearchbox W/OpenGLRenderer: Incorrectly called buildLayer on View: em, destroying layer...
11-12 13:56:05.447 1585-1608/system_process D/gralloc_ranchu: gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
11-12 13:56:05.466 2328-2472/com.google.android.gms I/Icing: Usage reports 0 indexed 0 rejected 0 imm upload true
11-12 13:56:05.486 2328-2504/com.google.android.gms I/Icing: Usage reports 0 indexed 0 rejected 0 imm upload true
11-12 13:56:05.499 1585-1920/system_process I/ActivityManager: Killing 2670:com.android.managedprovisioning/u0a8 (adj 15): empty #17
11-12 13:56:15.034 1585-1601/system_process W/ActivityManager: Activity destroy timeout for ActivityRecord{989c091 u0 com.example.dell.crash/.MainActivity t51 f}
11-12 13:56:15.075 2147-3230/com.google.android.googlequicksearchbox:search W/CronetSyncConnectionRcs: Upload content type not set.
11-12 13:56:17.062 3007-3007/com.example.dell.crash I/Process: Sending signal. PID: 3007 SIG: 9
11-12 13:56:17.093 1585-2485/system_process E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f849297e160
11-12 13:56:17.101 1585-2485/system_process D/OpenGLRenderer: endAllStagingAnimators on 0x7f84835bfc00 (RippleDrawable) with handle 0x7f847ee9ee60
11-12 13:56:17.131 1585-1920/system_process W/InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#9d97b24 attribute=null, token = android.os.BinderProxy#32922a9
11-12 13:56:17.165 1585-1920/system_process I/ActivityManager: Process com.example.dell.crash (pid 3007) has died
11-12 13:56:17.367 1585-1608/system_process W/AppOps: Finishing op nesting under-run: uid 1000 pkg android code 24 time=0 duration=0 nesting=0
11-12 13:56:17.409 2147-3268/com.google.android.googlequicksearchbox:search I/HotwordRecognitionRnr: Starting hotword detection.
11-12 13:56:17.413 2147-3269/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_starting com.google.android.apps.gsa.speech.audio.u#898b349
11-12 13:56:17.423 1202-1546/? E/audio_hw_generic: Error opening input stream format 1, channel_mask 0010, sample_rate 16000
11-12 13:56:17.444 1202-3273/? I/AudioFlinger: AudioFlinger's thread 0xf3b80000 ready to run
11-12 13:56:17.449 2147-2157/com.google.android.googlequicksearchbox:search I/art: Background sticky concurrent mark sweep GC freed 1466(93KB) AllocSpace objects, 0(0B) LOS objects, 9% free, 4MB/4MB, paused 25.294ms total 31.038ms
11-12 13:56:17.456 2147-3269/com.google.android.googlequicksearchbox:search I/MicrophoneInputStream: mic_started com.google.android.apps.gsa.speech.audio.u#898b349
11-12 13:56:17.493 2147-2147/com.google.android.googlequicksearchbox:search I/HotwordWorker: onReady
11-12 13:56:17.504 2328-3272/com.google.android.gms W/IcingInternalCorpora: getNumBytesRead when not calculated.
11-12 13:56:17.564 2328-2472/com.google.android.gms I/Icing: Usage reports 0 indexed 0 rejected 0 imm upload true
11-12 13:56:17.571 2328-2472/com.google.android.gms I/Icing: Usage reports 0 indexed 0 rejected 0 imm upload true
11-12 13:56:18.155 1202-1544/? W/AudioFlinger: write blocked for 408 msecs, 4 delayed writes, thread 0xf4500000
The .java file has the following block:
public class MainActivity extends AppCompatActivity {
Button btn1 = (Button) findViewById(R.id.button);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Main2Activity.class));
}
});
}
}
The XML file is as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.dell.crash.MainActivity">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="102dp"
android:id="#+id/button" />
</RelativeLayout>
I am using Android Studio 2.2.2
After
setContentView(R.layout.activity_main);
Add call like this
Button button = (Button) findViewById(R.id.button);
issue was you didn't created reference for button.
put Button btn1 = (Button) findViewById(R.id.button); in oncreate method.
The reason is you try add an event to your button but didn't show the reference id inside oncreate from where every app start its activity.
You should always instantiate button inside onCreate(). So your code should be like
public class MainActivity extends AppCompatActivity {
Button btn1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button) findViewById(R.id.button);
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Main2Activity.class));
}
});
}
}
If you init your btn1 variable in declarations section, it will run before the setContextView(...) function call. Put btn1 initialization after setContextView(...)!
public class MainActivity extends AppCompatActivity {
private Button btn1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = Button.class.cast(findViewById(R.id.button));
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Main2Activity.class));
}
});
}
}

Categories