java.lang.NoSuchMethodError E / AndroidRuntime:FATAL EXCEPTION:Thread-4进程:com.hikvision.open.app,PID

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java.lang.NoSuchMethodError E / AndroidRuntime:FATAL EXCEPTION:Thread-4进程:com.hikvision.open.app,PID相关的知识,希望对你有一定的参考价值。

我想制作一个应用程序来从网络摄像头获取视频,但有一个例外。我使用的工具是android Studio。

下载项目的链接:https://pan.baidu.com/s/1C0NGT73Ct0wfzQYoYUW5JQ

EXCEPTION:E / AndroidRuntime:FATAL EXCEPTION:Thread-4进程:com.hikvision.open.app,PID:20137 java.lang.NoSuchMethodError:没有直接方法(Ljavax / net / ssl / SSLContext;)类Lorg / apache中的V / HTTP /康恩/ SSL / SSLSocketFactory的;或者它的超类('org.apache.http.conn.ssl.SSLSocketFactory'的声明出现在/system/framework/framework.jar:classes3.dex中)位于com.hikvision.artemis.sdk.util.HttpUtil.sslClient( HttpUtil.java:499)at com.hikvision.artemis.sdk.util.HttpUtil.wrapClient(HttpUtil.java:478)at com.hikvision.artemis.sdk.util.HttpUtil.httpPost(HttpUtil.java:178)at com .hikvision.artemis.sdk.Client.execute(Client.java:53)at com.hikvision.artemis.sdk.ArtemisHttpUtil.doPostStringArtemis(ArtemisHttpUtil.java:182)

public void onClick(View view) 
    if (view.getId() == R.id.preview_button) 
        startActivity(new Intent(this, PreviewActivity.class));
     else if (view.getId() == R.id.find_button) 
        String stringhost = host.getText().toString().trim();
        String stringkey = key.getText().toString().trim();
        String stringsecret = secret.getText().toString().trim();
        if(TextUtils.isEmpty(stringhost))
            Toast.makeText(this, "所输内容为空,请确认后输入", LENGTH_SHORT).show();
            return;
        
        if(TextUtils.isEmpty(stringkey))
            Toast.makeText(this, "所输内容为空,请确认后输入", LENGTH_SHORT).show();
            return;
        
        if(TextUtils.isEmpty(stringsecret))
            Toast.makeText(this, "所输内容为空,请确认后输入", LENGTH_SHORT).show();
            return;
        
        new Thread()
            public void run()
                ArtemisConfig.host = stringhost;//"127.0.0.1:443"; // artemis网关服务器ip端口
                ArtemisConfig.appKey = stringkey;//"29180881";  // 秘钥appkey
                ArtemisConfig.appSecret = stringsecret;//"XO0wCAYGi4KV70ybjznx";// 秘钥appSecret

                /**
                 * STEP2:设置OpenAPI接口的上下文
                 */
                final String ARTEMIS_PATH = "/artemis";

                /**
                 * STEP3:设置接口的URI地址
                 */
                final String VechicleDataApi = ARTEMIS_PATH +"/api/fms/v3/human/findSnapHuman";
                Map<String,String> path = new HashMap<String,String>(2)
                    
                        put("https://",VechicleDataApi);
                    
                ;

                /**
                 * STEP4:设置参数提交方式
                 */
                //String contentType = "application/json";

                /**
                 * STEP5:组装请求参数
                 */
                JSONObject jsonBody = new JSONObject();
                try
                    jsonBody.put("deviceCodes","-1");
                    jsonBody.put("sex",-1);
                    jsonBody.put("beginDate","2017-09-01 12:00:00");
                    jsonBody.put("endDate","2017-09-12 12:00:00");
                    jsonBody.put("similarityMin",0.1);
                    jsonBody.put("similarityMax",1);
                    jsonBody.put("picUrl", "http://10.33.44.61:6501/pic?=d82i649e*4ebi05f-646618-52c3ca0764e4cai5b1*=1d6s4*=6dpi*=1d3i4t2pe*m5i13=-1050e3-10z1cas=630bd1");
                    jsonBody.put("pageNo",1);
                    jsonBody.put("pageSize",12);
                catch(JSONException e)
                    e.printStackTrace();
                    Message message = Message.obtain();
                    message.what = ERROR;
                
                String body = jsonBody.toString();
                /**
                 * STEP6:调用接口
                 */
                String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json");// post请求application/json类型参数
                Message message = Message.obtain();
                message.what = SUCCESS;
                message.obj = result;
                FindURL fi = new FindURL();
                fi.setUrl(result);
            
        .start();
    

的build.gradle:

    apply plugin: 'com.android.application'

android 
    compileSdkVersion 28
    defaultConfig 
        applicationId "com.hikvision.open.app"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    

    buildTypes 
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        
    
    compileOptions 
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    
    //useLibrary 'org.apache.http.legacy'



dependencies 
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:support-annotations:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.blankj:utilcode:1.20.3'
    implementation files('libs/artemis-http-client-1.0-SNAPSHOT.jar')

当我使用runOnUiThread而不是处理程序时,代码:

@Override
protected void onCreate(Bundle savedInstanceState) 
    super.onCreate(savedInstanceState);
    super.setContentView(R.layout.activity_main);
    Button mPreviewButton = (Button) findViewById(R.id.preview_button);
    mPreviewButton.setOnClickListener(MainActivity.this);
    Button mfindButton = (Button) findViewById(R.id.find_button);
    mfindButton.setOnClickListener(MainActivity.this);
    requestPermissions();

    host = findViewById(R.id.text_input_host);
    key = findViewById(R.id.text_input_key);
    secret = findViewById(R.id.text_input_secret);

    Toast.makeText(this, "请先获得地址,之后实时预览", LENGTH_LONG).show();


@Override
public void onClick(View view) 
    if (view.getId() == R.id.preview_button) 
        startActivity(new Intent(this, PreviewActivity.class));
     else if (view.getId() == R.id.find_button) 
        String stringhost = host.getText().toString().trim();
        String stringkey = key.getText().toString().trim();
        String stringsecret = secret.getText().toString().trim();
        if(TextUtils.isEmpty(stringhost))
            Toast.makeText(this, "所输内容为空,请确认后输入", LENGTH_SHORT).show();
            return;
        
        if(TextUtils.isEmpty(stringkey))
            Toast.makeText(this, "所输内容为空,请确认后输入", LENGTH_SHORT).show();
            return;
        
        if(TextUtils.isEmpty(stringsecret))
            Toast.makeText(this, "所输内容为空,请确认后输入", LENGTH_SHORT).show();
            return;
        
        MainActivity.this. runOnUiThread(new Runnable() 
            @Override
            public void run() 
                // refresh ui 的操作代码
                ArtemisConfig.host = stringhost;//"127.0.0.1:443"; // artemis网关服务器ip端口
                ArtemisConfig.appKey = stringkey;//"29180881";  // 秘钥appkey
                ArtemisConfig.appSecret = stringsecret;//"XO0wCAYGi4KV70ybjznx";// 秘钥appSecret

                /**
                 * STEP2:设置OpenAPI接口的上下文
                 */
                final String ARTEMIS_PATH = "/artemis";

                /**
                 * STEP3:设置接口的URI地址
                 */
                final String VechicleDataApi = ARTEMIS_PATH +"/api/fms/v3/human/findSnapHuman";
                Map<String,String> path = new HashMap<String,String>(2)
                    
                        put("https://",VechicleDataApi);
                    
                ;

                /**
                 * STEP4:设置参数提交方式
                 */
                //String contentType = "application/json";

                /**
                 * STEP5:组装请求参数
                 */
                JSONObject jsonBody = new JSONObject();
                try
                    jsonBody.put("deviceCodes","-1");
                    jsonBody.put("sex",-1);
                    jsonBody.put("beginDate","2017-09-01 12:00:00");
                    jsonBody.put("endDate","2017-09-12 12:00:00");
                    jsonBody.put("similarityMin",0.1);
                    jsonBody.put("similarityMax",1);
                    jsonBody.put("picUrl", "http://10.33.44.61:6501/pic?=d82i649e*4ebi05f-646618-52c3ca0764e4cai5b1*=1d6s4*=6dpi*=1d3i4t2pe*m5i13=-1050e3-10z1cas=630bd1");
                    jsonBody.put("pageNo",1);
                    jsonBody.put("pageSize",12);
                catch(JSONException e)
                    e.printStackTrace();
                    /*Message message = Message.obtain();
                    message.what = ERROR;*/
                    Toast.makeText(MainActivity.this, "查询错误,请检查无误后输入", LENGTH_SHORT).show();
                
                String body = jsonBody.toString();
                /**
                 * STEP6:调用接口
                 */
                String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json");// post请求application/json类型参数
                /*Message message = Message.obtain();
                message.what = SUCCESS;
                message.obj = result;*/
                Toast.makeText(MainActivity.this, "查询成功,请点击预览按钮", LENGTH_SHORT).show();
                Toast.makeText(MainActivity.this, "返回信息:" + result, LENGTH_LONG).show();
                FindURL fi = new FindURL();
                fi.setUrl(result);
            
        );
    



/**
 * 获取手机存储读写权限
 */
private void requestPermissions() 
    int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
    if (permissionCheck == PackageManager.PERMISSION_DENIED) 
        ActivityCompat.requestPermissions(this, (new String[]Manifest.permission.WRITE_EXTERNAL_STORAGE), 10);
    

新的EXCEPTION已经发生:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hikvision.open.app, PID: 10719
java.lang.NoSuchMethodError: No direct method <init>(Ljavax/net/ssl/SSLContext;)V in class Lorg/apache/http/conn/ssl/SSLSocketFactory; or its super classes (declaration of 'org.apache.http.conn.ssl.SSLSocketFactory' appears in /system/framework/framework.jar:classes3.dex)
    at com.hikvision.artemis.sdk.util.HttpUtil.sslClient(HttpUtil.java:499)
    at com.hikvision.artemis.sdk.util.HttpUtil.wrapClient(HttpUtil.java:478)
    at com.hikvision.artemis.sdk.util.HttpUtil.httpPost(HttpUtil.java:178)
    at com.hikvision.artemis.sdk.Client.execute(Client.java:53)
    at com.hikvision.artemis.sdk.ArtemisHttpUtil.doPostStringArtemis(ArtemisHttpUtil.java:182)
    at com.hikvision.open.app.MainActivity$1.run(MainActivity.java:151)
    at android.app.Activity.runOnUiThread(Activity.java:6281)
    at com.hikvision.open.app.MainActivity.onClick(MainActivity.java:99)
    at android.view.View.performClick(View.java:6897)
    at android.widget.TextView.performClick(TextView.java:12693)
    at android.view.View$PerformClick.run(View.java:26101)
    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:6944)
    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)

我需要帮助!!!请!!

答案

当您尝试从无法执行的线程更新视图时,可能会出现此错误。 new Thread()类创建一个不同的线程,因此android主线程不允许从主线程以外的其他线程更新UI。您需要使用runOnUiThread来更新您的视图。

您可以使用runOnUiThread,如下所示:

runOnUiThread(new Runnable() 
    public void run()                      
        // your code to update the UI thread here               
    
);

以上是关于java.lang.NoSuchMethodError E / AndroidRuntime:FATAL EXCEPTION:Thread-4进程:com.hikvision.open.app,PID的主要内容,如果未能解决你的问题,请参考以下文章