gpt4 book ai didi

android - java.lang.NoClassDefFoundError : com. google.api.client.http.javanet.NetHttpTransport 错误

转载 作者:行者123 更新时间:2023-11-29 02:05:36 27 4
gpt4 key购买 nike

我正在尝试使用适用于 Android 的 Google Places API,但每当我尝试运行我的应用程序时,我都会收到此错误:

04-19 18:27:16.094: E/AndroidRuntime(531): Caused by: java.lang.NoClassDefFoundError: com.google.api.client.http.javanet.NetHttpTransport
04-19 18:27:16.094: E/AndroidRuntime(531): at com.android.FoodFinder.MainActivity.<clinit>(MainActivity.java:38)

这是我的代码

package com.android.FoodFinder;


import java.io.IOException;

import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.http.json.JsonHttpParser;
import com.google.api.client.json.jackson.JacksonFactory;

import android.app.ListActivity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends ListActivity
{

private float distance;
private Location location;
private double latitude;
private double longitude;
private static String keyString = "0JVolnSwRg8xLH0J6d9rUwQH-e770dlWn3kcRuA";
private static String urlString = "https://maps.googleapis.com/maps/api/place/search/json?";
private static final HttpTransport transport = new NetHttpTransport();

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

if(location == null)
{
latitude = 0;
longitude = 0;
}
else
{
latitude = location.getLatitude();
longitude = location.getLongitude();
}

final EditText distanceEdit = (EditText)findViewById(R.id.distance);

final Button confirm = (Button)findViewById(R.id.confirm);
confirm.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
try
{
distance = Float.parseFloat(distanceEdit.getText().toString());
search(distance);
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
}

private void search(float d) throws IOException
{
HttpRequestFactory hrfactory = createRequestFactory(transport);
HttpRequest request = hrfactory.buildGetRequest(new GenericUrl(urlString));
request.getUrl().put("key", keyString);
request.getUrl().put("location", latitude + ", " + longitude);
request.getUrl().put("types", "restaurant");
request.getUrl().put("radius", distance);
request.getUrl().put("sensor", "false");

}

private static HttpRequestFactory createRequestFactory(final HttpTransport transport)
{
return transport.createRequestFactory(new HttpRequestInitializer()
{

public void initialize(HttpRequest request) throws IOException
{
request.addParser(new JsonHttpParser(new JacksonFactory()));
}
});
}

}

错误在:

private static final HttpTransport transport = new NetHttpTransport();

我已将以下 jar 文件添加到我的构建路径中:

  • commons-logging-1.1.1

  • google-http-client-1.8.3-beta

  • google-http-client-android2-1.8.3-beta

  • google-http-client-android3-1.8.3-beta

  • google-http-client-appengine-1.8.3-beta

  • google-oauth-client-1.8.0-beta

  • gson-2.1

  • guava-r09

  • guava-11.0.2

  • httpclient-4.0.3

  • httpcore-4.0.1

  • jackson-core-asl-1.9.4

  • jdo2-api-2.3-eb

  • json-20080701

  • jsr305-1.3.9

  • junit-4.8.2

  • protobuf-java-2.2.0

  • transaction-api-1.1

  • xpp3-1.1.4c

  • google-api-client-1.8.0-beta

  • google-api-client-appengine-1.8.0-beta

  • google-api-client-servlet-1.8.0

但我仍然设法获得 NoClassDefFoundExeception。我做错了什么?

最佳答案

我认为问题出在添加 jar 上,试试这个在根名称/libs(不是/lib)和 Project => Properties => Java Build Path => Libraries => Add JAR ...

您可以找到更多帮助 herehere

关于android - java.lang.NoClassDefFoundError : com. google.api.client.http.javanet.NetHttpTransport 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10235034/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com