Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.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
Java Android Studio崩溃谷歌地理Api_Java_Android_Android Asynctask - Fatal编程技术网

Java Android Studio崩溃谷歌地理Api

Java Android Studio崩溃谷歌地理Api,java,android,android-asynctask,Java,Android,Android Asynctask,我的应用程序有点问题。它崩溃了,当我在Debug上运行它时,它什么也没说。这就是崩溃发生的地方: public class GeoTask extends AsyncTask<String,Void,ArrayList<Double>>{ @Override protected ArrayList<Double> doInBackground(String... params) { ArrayList<Double> geo_ll =

我的应用程序有点问题。它崩溃了,当我在Debug上运行它时,它什么也没说。这就是崩溃发生的地方:

public class GeoTask extends AsyncTask<String,Void,ArrayList<Double>>{

@Override
protected ArrayList<Double> doInBackground(String... params) {

    ArrayList<Double> geo_ll = new ArrayList<>();
    HttpsURLConnection connection = null;
    BufferedReader reader = null;
    String result ="";

    try {
        URL url = new URL("https://maps.googleapis.com/maps/api/geocode/json?address=New York&key=AIzaSyBpaGooTWbj7QbN_qdW4pf-OvAi2OOhpG4");

        connection = (HttpsURLConnection) url.openConnection();
        int code = connection.getResponseCode();
        int a = 1;

        if (connection.getResponseCode() != HttpURLConnection.HTTP_OK){

            return null;
        }

        reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));



        String line = reader.readLine();
        while(line!=null){
            result+=line;
            line = reader.readLine();
        }

        JSONObject object = new JSONObject(result);
        JSONArray results = object.getJSONArray("results");
        JSONObject zero = results.getJSONObject(0);
        JSONObject geometry = zero.getJSONObject("geometry");
        JSONObject location = geometry.getJSONObject("location");
        double latitude = location.getDouble("lat");
        double longitude = location.getDouble("lng");

        geo_ll.add(latitude);
        geo_ll.add(longitude);

        return geo_ll;

    } catch (MalformedURLException e) {
        Toast.makeText(NewItemActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
    } catch (JSONException e) {
        Toast.makeText(NewItemActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
    } catch (IOException e) {
        Toast.makeText(NewItemActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
    }

    return null;
}
公共类GeoTask扩展了AsyncTask{
@凌驾
受保护的ArrayList doInBackground(字符串…参数){
ArrayList geo_ll=新的ArrayList();
HttpsURLConnection连接=null;
BufferedReader reader=null;
字符串结果=”;
试一试{
URL=新URL(“https://maps.googleapis.com/maps/api/geocode/json?address=New 约克和基=AIzaSyBpaGooTWbj7QbN_qdW4pf-OvAi2OOhpG4“;
connection=(HttpsURLConnection)url.openConnection();
int code=connection.getResponseCode();
INTA=1;
if(connection.getResponseCode()!=HttpURLConnection.HTTP\u确定){
返回null;
}
reader=new BufferedReader(new InputStreamReader(connection.getInputStream());
字符串行=reader.readLine();
while(行!=null){
结果+=行;
line=reader.readLine();
}
JSONObject对象=新的JSONObject(结果);
JSONArray results=object.getJSONArray(“结果”);
JSONObject零=结果。getJSONObject(0);
JSONObject几何体=零。getJSONObject(“几何体”);
JSONObject location=geometry.getJSONObject(“位置”);
双纬度=位置。getDouble(“lat”);
双经度=位置。getDouble(“lng”);
地理位置添加(纬度);
地理位置添加(经度);
返回geo_ll;
}捕获(格式错误){
Toast.makeText(NewItemActivity.this,e.getMessage(),Toast.LENGTH_SHORT.show();
}捕获(JSONException e){
Toast.makeText(NewItemActivity.this,e.getMessage(),Toast.LENGTH_SHORT.show();
}捕获(IOE异常){
Toast.makeText(NewItemActivity.this,e.getMessage(),Toast.LENGTH_SHORT.show();
}
返回null;
}
我看不出有什么不对劲。我已经检查了100多次,但还是发生了。它实际上工作过一次,之后就再也不工作了

请帮忙。
谢谢您的时间。

oops api密钥在那里,我将更改它以获得一个新的,现在我将继续测试它,对此表示抱歉。
Toast.makeText必须在UI线程上调用,而整个
doInBackground
则在后台线程上调用。使用
e.printStackTrace()
并查看日志,而不是向所有人显示。是的,我删除了它,但它仍然会崩溃。发布错误堆栈跟踪。我如何找到堆栈跟踪?因为我没有看到任何错误