android - http 连接错误 javax.net.ssl.SSLPeerUnverifiedException : No peer certificate

标签 android ssl

在下面的代码中,我正在做的是从 Web 服务获取微调项。在项目选择上,完成了一些过程。 问题是它没有从服务器向微调器获取数据。

Frnt_mapActivty1.java

  /*****************************FOR LOCATION FOR**************************************/
//Download JSON file AsyncTask
public class LocationList extends AsyncTask<Void, Void, Void> {
    JSONObject jsonobject;
    JSONArray jsonarray;


@Override
    protected Void doInBackground(Void... params) {
        // Locate the WorldPopulation Class
        worldlocation = new ArrayList<LocationBeams>();
        // Create an array to populate the spinner
        world_locationlist = new ArrayList<String>();
        // JSON file URL address
        jsonobject = JSONfunctions.getJSONfromURL(Wservices.mGetLocationURL);
        try {
            // Locate the NodeList name
            jsonarray = jsonobject.getJSONArray("location");
            for (int i = 0; i < jsonarray.length(); i++) {
                jsonobject = jsonarray.getJSONObject(i);
                LocationBeams worldpop = new LocationBeams();
                worldpop.setTerm_id(jsonobject.optString("term_id"));
                worldpop.setName(jsonobject.optString("name"));
                worldpop.setSlug(jsonobject.optString("slug"));

                worldlocation.add(worldpop);
                world_locationlist.add(jsonobject.optString("name"));
            }
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return null;
    }
    @Override
    protected void onPostExecute(Void args) {
        // Locate the spinner in activity_main.xml
        Spinner mySpinner = (Spinner)findViewById(R.id.spin_location);
        // Spinner adapter
        mySpinner.setAdapter(new ArrayAdapter<String>(Frnt_mapActivity1.this,
                android.R.layout.simple_spinner_dropdown_item,world_locationlist));
        // Spinner on item click listener
        mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> arg0,
                                       View arg1, int position, long arg3) {
                // TODO Auto-generated method stub


                txtlocation.setText(worldlocation.get(position).getSlug());

            }
            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub
            }
        });

        if(mDialog!=null && mDialog.isShowing()){
            mDialog.dismiss();
        }
    }
}

日志

 Error in http connection javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

 Error converting result java.lang.NullPointerException: lock == null
 Error parsing data org.json.JSONException: End of input at character 0 of 

 FATAL EXCEPTION: AsyncTask #2
Process: com.towncitycards, PID: 29656
java.lang.RuntimeException: An error occured while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:300)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:841)
 Caused by: java.lang.NullPointerException: println needs a message
    at android.util.Log.println_native(Native Method)
    at android.util.Log.e(Log.java:334)
    at app.towncitycards.activities.Frnt_mapActivity1$LocationList.doInBackground(Frnt_mapActivity1.java:1725)
    at app.towncitycards.activities.Frnt_mapActivity1$LocationList.doInBackground(Frnt_mapActivity1.java:1698)
    at android.os.AsyncTask$2.call(AsyncTask.java:288)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
    at java.lang.Thread.run(Thread.java:841) 

最佳答案

Caused by: java.lang.NullPointerException: println needs a message at android.util.Log.println_native(Native Method)

问题

Log.e("Error", e.getMessage());

e.getMessage()为空

NullPointerException is thrown when an application attempts to use an object reference that has the null value

检查

e.getMessage()==null

尝试

 if(e.getMessage()==null)
 {
    Log.e("Error", " "+e.getMessage());
    e.printStackTrace();
 }
else
 {
   Log.e("Error", e.getMessage());
    e.printStackTrace();
 }

阅读 NullPointerException : println needs a message in android

关于android - http 连接错误 javax.net.ssl.SSLPeerUnverifiedException : No peer certificate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42777487/

相关文章:

java - 网络错误和异步困惑

Android Facebook Sdk 4.11.0 如何在没有任何链接或图像的情况下将简单的状态更新发布到墙上

php - curl 错误 : SSL certificate error: self signed certificate in certificate chain

java - 安全网络 - ServerSocket 与 SSLServerSocketFactory?

java - Android:按下后退按钮时提示用户保存更改

android - 使用笔记本电脑触摸板在 Android Studio 中滚动有时不起作用

android - 我想知道在 Android 7 上录制通话是否可能,是否会实现?

c# - HTTP Get请求错误 "Authentication failed because the remote party has closed the transport stream."

ssl - activemq-cpp c++​​ 客户端如何使用 ssl url 连接服务器

java - SSLEngine:在成功握手后展开时无效的 TLS 填充数据