Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调用Switch.setChecked(true)时,Android应用程序OKHTTP Websocket onFailure()连接关闭_Android_Android Layout_Https_Websocket - Fatal编程技术网

调用Switch.setChecked(true)时,Android应用程序OKHTTP Websocket onFailure()连接关闭

调用Switch.setChecked(true)时,Android应用程序OKHTTP Websocket onFailure()连接关闭,android,android-layout,https,websocket,Android,Android Layout,Https,Websocket,我正在android studio emulator中开发一个websocket应用程序,显然一切正常,直到程序执行“Switch.setChecked(true)”为止。 当程序执行“Switch.setChecked(true)”时,调用“public void onFailure(WebSocket-WebSocket,Throwable t,Response-Response)”方法并关闭连接 我认为这是侦听器中的一些递归问题,但是如果侦听器中的“onCheckedChanged()”函

我正在android studio emulator中开发一个websocket应用程序,显然一切正常,直到程序执行“Switch.setChecked(true)”为止。 当程序执行“Switch.setChecked(true)”时,调用“public void onFailure(WebSocket-WebSocket,Throwable t,Response-Response)”方法并关闭连接

我认为这是侦听器中的一些递归问题,但是如果侦听器中的“onCheckedChanged()”函数没有任何代码,那么问题仍然存在

注: 我正在使用https/wss。 安全websocket服务器由我在esp32中编程

谢谢你的帮助

private Switch lampSwitch;

protected void onCreate(Bundle savedInstanceState)
{  
    ...

    lampSwitch = (Switch) findViewById(R.id.lampSwitch);
    lampSwitch.setOnCheckedChangeListener(new lampSwitchListener());

    ...
}


private static final String TAG = "FragmentActivity";
private String sendValue;

private class lampSwitchListener implements CompoundButton.OnCheckedChangeListener
{
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
    {
        Log.d(TAG, "onCheckedChanged: test");

        if (isChecked)
        {
            sendValue = "{\"lamp\":\"ON\"}";
        }
        else
        {
            sendValue = "{\"lamp\":\"OFF\"}";
        }
        send_Ws_Message(2, sendValue);
    }
}


private void process_Message( ByteString input )    
{
    ByteString b = input.substring(1);    // offset 1 position.
    String message = b.utf8();    // convert from ByteString to String.
    

    Log.d("MSG: ", message);
    Log.d("length: ", String.valueOf(message.length() ) );
    
    
    JSONObject jObject = null;
    try
    {
        jObject = new JSONObject(message);
    } catch (JSONException e) {
        e.printStackTrace();
    }


    String lamp = null;
    try
    {
        lamp = jObject.getString("lamp");
    } catch (JSONException e) {
        e.printStackTrace();
    }


    if ( lamp.equals("ON") )
    {
        Log.d("lamp: ", lamp);
        Log.d("lamp.length: ", String.valueOf(lamp.length() ));


        lampSwitch.setChecked(true);    // this code line close client websocket connection
    }
}
日志:

2020-10-03 00:37:44.898 6218-6218/? I/mple.myfirstap: Not late-enabling -Xcheck:jni (already on)
2020-10-03 00:37:44.914 6218-6218/? I/mple.myfirstap: Unquickening 12 vdex files!
2020-10-03 00:37:44.915 6218-6218/? W/mple.myfirstap: Unexpected CPU variant for X86 using defaults: x86
2020-10-03 00:37:45.070 6218-6218/com.example.myfirstapp D/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
2020-10-03 00:37:45.072 6218-6218/com.example.myfirstapp D/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
2020-10-03 00:37:45.082 6218-6243/com.example.myfirstapp D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2020-10-03 00:37:45.088 6218-6243/com.example.myfirstapp D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2020-10-03 00:37:45.092 6218-6243/com.example.myfirstapp D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2020-10-03 00:37:45.201 6218-6218/com.example.myfirstapp W/mple.myfirstap: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2020-10-03 00:37:45.201 6218-6218/com.example.myfirstapp W/mple.myfirstap: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2020-10-03 00:37:45.295 6218-6241/com.example.myfirstapp D/HostConnection: HostConnection::get() New Host Connection established 0xee254710, tid 6241
2020-10-03 00:37:45.299 6218-6241/com.example.myfirstapp 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 GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0 
2020-10-03 00:37:45.301 6218-6241/com.example.myfirstapp W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2020-10-03 00:37:45.306 6218-6241/com.example.myfirstapp D/EGL_emulation: eglCreateContext: 0xee064eb0: maj 3 min 0 rcv 3
2020-10-03 00:37:45.323 6218-6241/com.example.myfirstapp D/EGL_emulation: eglMakeCurrent: 0xee064eb0: ver 3 0 (tinfo 0xee3b5630) (first time)
2020-10-03 00:37:45.343 6218-6241/com.example.myfirstapp I/Gralloc4: mapper 4.x is not supported
2020-10-03 00:37:45.344 6218-6241/com.example.myfirstapp D/HostConnection: createUnique: call
2020-10-03 00:37:45.344 6218-6241/com.example.myfirstapp D/HostConnection: HostConnection::get() New Host Connection established 0xee253ed0, tid 6241
2020-10-03 00:37:45.369 6218-6241/com.example.myfirstapp D/goldfish-address-space: allocate: Ask for block of size 0x100
2020-10-03 00:37:45.369 6218-6241/com.example.myfirstapp D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3fc7ba000 size 0x2000
2020-10-03 00:37:45.375 6218-6241/com.example.myfirstapp 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 GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0 
2020-10-03 00:37:47.795 6218-6218/com.example.myfirstapp W/mple.myfirstap: Accessing hidden method Landroid/graphics/FontFamily;-><init>()V (greylist-max-q, reflection, denied)
2020-10-03 00:37:47.797 6218-6218/com.example.myfirstapp E/TypefaceCompatApi26Impl: Unable to collect necessary methods for class java.lang.NoSuchMethodException
    java.lang.NoSuchMethodException: android.graphics.FontFamily.<init> []
        at java.lang.Class.getConstructor0(Class.java:2332)
        at java.lang.Class.getConstructor(Class.java:1728)
        at androidx.core.graphics.TypefaceCompatApi26Impl.obtainFontFamilyCtor(TypefaceCompatApi26Impl.java:321)
        at androidx.core.graphics.TypefaceCompatApi26Impl.<init>(TypefaceCompatApi26Impl.java:84)
        at androidx.core.graphics.TypefaceCompatApi28Impl.<init>(TypefaceCompatApi28Impl.java:36)
        at androidx.core.graphics.TypefaceCompat.<clinit>(TypefaceCompat.java:47)
        at androidx.core.graphics.TypefaceCompat.create(TypefaceCompat.java:190)
        at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
        at android.widget.TextView.resolveStyleAndSetTypeface(TextView.java:2183)
        at android.widget.TextView.setTypefaceFromAttrs(TextView.java:2154)
        at android.widget.TextView.applyTextAppearance(TextView.java:4105)
        at android.widget.TextView.<init>(TextView.java:1630)
        at android.widget.TextView.<init>(TextView.java:990)
        at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:99)
        at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:95)
        at androidx.appcompat.app.AppCompatViewInflater.createTextView(AppCompatViewInflater.java:182)
        at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
        at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1407)
        at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1457)
        at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1059)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:995)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.example.myfirstapp.DisplayMessageActivity.onCreate(DisplayMessageActivity.java:163)
        at android.app.Activity.performCreate(Activity.java:7995)
        at android.app.Activity.performCreate(Activity.java:7979)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        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)
2020-10-03 00:37:49.599 6218-6251/com.example.myfirstapp D/FragmentActivity: onFailure: caca
2020-10-03 00:37:44.8986218-6218/?I/mple.myfirstap:未延迟启用-Xcheck:jni(已启用)
2020-10-03 00:37:44.914 6218-6218/? I/mple.myfirstap:取消加速12个vdex文件!
2020-10-03 00:37:44.915 6218-6218/? W/mple.myfirstap:使用默认值的X86的意外CPU变量:X86
2020-10-03 00:37:45.070 6218-6218/com.example.myfirstapp D/NetworkSecurityConfig:使用资源网络的网络安全配置
2020-10-03 00:37:45.072 6218-6218/com.example.myfirstapp D/NetworkSecurityConfig:使用资源网络的网络安全配置
2020-10-03 00:37:45.082 6218-6243/com.example.myfirstapp D/libEGL:loaded/vendor/lib/egl/libEGL_.so
2020-10-03 00:37:45.088 6218-6243/com.example.myfirstapp D/libEGL:loaded/vendor/lib/egl/libGLESv1_CM_emulation.so
2020-10-03 00:37:45.092 6218-6243/com.example.myfirstapp D/libEGL:loaded/vendor/lib/egl/libGLESv2_emulation.so
2020-10-03 00:37:45.201 6218-6218/com.example.myfirstapp W/mple.myfirstap:访问隐藏方法Landroid/view/view;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z(灰色列表,允许反射)
2020-10-03 00:37:45.201 6218-6218/com.example.myfirstapp W/mple.myfirstap:访问隐藏方法Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V(灰色列表,允许反射)
2020-10-03 00:37:45.295 6218-6241/com.example.myfirstapp D/HostConnection:HostConnection::get()已建立新主机连接0xee254710,tid 6241
2020-10-03 00:37:45.299 6218-6241/com.example.myfirstapp D/HostConnection:HostComposition ext ANDROID\u EMU\u CHECKSUM\u HELPER\u v1安卓\u EMU native\u sync\u v2安卓\u EMU native\u sync\u v3安卓\u EMU native\u sync\u v4安卓\u EMU dma\u v1安卓\u EMU直接\u mem \u安卓\u主机\u组合\u安卓\u EMU主机\u安卓\u EMU sync\u v2ANDROID\u EMU\u deferred\u vulkan\u命令ANDROID\u EMU\u vulkan\u可选字符串ANDROID\u EMU\u vulkan\u创建资源\u符合要求ANDROID\u EMU\u YUV\u缓存ANDROID\u EMU异步\u取消映射\u缓冲区ANDROID\u EMU vulkan\u忽略\u处理ANDROID\u EMU vulkan\u空闲内存\u同步GL\u OES\u EGL\u图像\u外部essl3 GL\u OES\u对象顶点数组GL_KHR_纹理_压缩_astc_ldr安卓_EMU gles_max_版本_3_0
2020-10-03 00:37:45.301 6218-6241/com.example.myfirstapp W/OpenGLRenderer:未能选择保留EGL交换行为的配置,正在重试,但没有。。。
2020-10-03 00:37:45.306 6218-6241/com.example.myfirstapp D/EGL_仿真:eglCreateContext:0xee064eb0:maj 3 min 0 rcv 3
2020-10-03 00:37:45.323 6218-6241/com.example.myfirstapp D/EGL_仿真:eglMakeCurrent:0xee064eb0:ver 30(tinfo 0xee3b5630)(第一次)
2020-10-03 00:37:45.343 6218-6241/com.example.myfirstapp I/Gralloc4:mapper 4.x不受支持
2020-10-03 00:37:45.344 6218-6241/com.example.myfirstapp D/HostConnection:createUnique:call
2020-10-03 00:37:45.344 6218-6241/com.example.myfirstapp D/HostConnection:HostConnection::get()已建立新主机连接0xee253ed0,tid 6241
2020-10-03 00:37:45.369 6218-6241/com.example.myfirstapp D/金鱼地址空间:分配:请求大小为0x100的块
2020-10-03 00:37:45.369 6218-6241/com.example.myfirstapp D/金鱼地址空间:分配:ioctl分配返回的偏移量0x3fc7ba000大小0x2000
2020-10-03 00:37:45.375 6218-6241/com.example.myfirstapp D/HostConnection:HostComposition ext ANDROID\u EMU\u CHECKSUM\u HELPER\u v1安卓\u EMU native\u sync\u v2安卓\u EMU native\u sync\u v3安卓\u EMU native\u sync\u v4安卓\u EMU dma\u v1安卓\u EMU direct\u mem\u安卓\u EMU主机\u composition\u安卓\u EMU主机\u sync\u v1安卓\u EMU主机组合ANDROID\u EMU\u deferred\u vulkan\u命令ANDROID\u EMU\u vulkan\u可选字符串ANDROID\u EMU\u vulkan\u创建资源\u符合要求ANDROID\u EMU\u YUV\u缓存ANDROID\u EMU异步\u取消映射\u缓冲区ANDROID\u EMU vulkan\u忽略\u处理ANDROID\u EMU vulkan\u空闲内存\u同步GL\u OES\u EGL\u图像\u外部essl3 GL\u OES\u对象顶点数组GL_KHR_纹理_压缩_astc_ldr安卓_EMU gles_max_版本_3_0
2020-10-03 00:37:47.795 6218-6218/com.example.myfirstapp W/mple.myfirstap:访问隐藏方法Landroid/graphics/FontFamily;->()V(greylist-max-q,反射,拒绝)
2020-10-03 00:37:47.797 6218-6218/com.example.myfirstapp E/typefacecompatipapi26impl:无法收集类java.lang.NoSuchMethodException所需的方法
java.lang.NoSuchMethodException:android.graphics.FontFamily。[]
位于java.lang.Class.getConstructor0(Class.java:2332)
位于java.lang.Class.getConstructor(Class.java:1728)
在androidx.core.graphics.TypefaceCompatipI26Impl.ActainFontFamilyTor(TypefaceCompatipI26Impl.java:321)中
在androidx.core.graphics.typefacecompatipapi26impl。(typefacecompatipapi26impl.java:84)
在androidx.core.graphics.typefacecompatipapi28impl.(typefacecompatipapi28impl.java:36)
位于androidx.core.graphics.TypefaceCompat.(TypefaceCompat.java:47)
在androidx.core.graphics.TypefaceCompat.create(TypefaceCompat.java:190)中
位于androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
位于android.widget.TextView.resolveStyleAndSetTypeface(TextView.java:2183)
在android.widget.TextView.setTypefaceFromAttrs(TextView.java:2154)中
在android.widget.TextView.applyTextApp上
slider = (SeekBar) findViewById(R.id.slider);
slider.setOnSeekBarChangeListener(new sliderListener());
@Override
protected void onCreate(Bundle savedInstanceState)
{
    ...

    lampSwitch = (Switch) findViewById(R.id.lampSwitch);
    lampSwitch.setChecked(true);
    lampSwitch.setOnCheckedChangeListener(new lampSwitchListener());

    ...
@Override
protected void onCreate(Bundle savedInstanceState)
{
    ...

    lampSwitch = (Switch) findViewById(R.id.lampSwitch);
    lampSwitch.setOnCheckedChangeListener(new lampSwitchListener());
    lampSwitch.setChecked(true);    

    ...
if ( lamp.equals("ON") )
{
    Log.d("lamp: ", lamp);
    Log.d("lamp.length: ", String.valueOf(lamp.length() ) );

    lampSwitch.setOnCheckedChangeListener( null );
    lampSwitch.setChecked(true);    
    lampSwitch.setOnCheckedChangeListener(new lampSwitchListener());
}
runOnUiThread(new Runnable()
{
    @Override
    public void run()
    {
        lampSwitch.setOnCheckedChangeListener( null );
        lampSwitch.setChecked(true);
        lampSwitch.setOnCheckedChangeListener(new lampSwitchListener());
    }
});