在下面的代码中,我正在做的是从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)
答案 0 :(得分:0)
引起:java.lang.NullPointerException:println需要一条消息 在android.util.Log.println_native(原生方法)
问题
Log.e("Error", e.getMessage());
e.getMessage()为空
当应用程序尝试使用时抛出NullPointerException 具有空值
的对象引用
检查
<强> 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