Autore Topic: Utilizzo Api Mashape + maven  (Letto 563 volte)

Offline pizzom

  • Nuovo arrivato
  • *
  • Post: 1
  • Respect: 0
    • Mostra profilo
Utilizzo Api Mashape + maven
« il: 09 Dicembre 2014, 18:25:08 CET »
0
Ciao, sono alle prime armi. Sto cercando di Utilizzare delle API di Mashape per un progettino Android ma ho delle difficolta. Ho semplicemente creato un progetto utilizzando maven e poi lo ho aperto con eclipse. Sucessivamente ho inserito il codice di esempio ma all'avvio mi da un errore che non riesco ad identificare.
Ecco la pagina di esempio https://www.mashape.com/george-vustrey/ultimate-weather-forecasts
Vi ringrazio anticipatamente per l'aiuto


Codice (Java): [Seleziona]
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

public class HelloAndroidActivity extends Activity {

    /**
     * Called when the activity is first created.
     * @param savedInstanceState If the activity is being re-initialized after
     * previously being shut down then this Bundle contains the data it most
     * recently supplied in onSaveInstanceState(Bundle). <b>Note: Otherwise it is null.</b>
     */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
                        HttpResponse<JsonNode> response = Unirest.get("https://george-vustrey-weather.p.mashape.com/api.php?location=Los+Angeles")
                                        .header("X-Mashape-Key", "nYuSoBlzj8mshhWdAT6LdP4t8mJDp1IyDHXjsneDE3i4ZTCr3N")
                                        .asJson();
                } catch (UnirestException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(your.company.R.menu.main, menu);
        return true;
    }

}

ecco il Logcat

Codice: [Seleziona]
12-09 12:00:46.229: I/dalvikvm(1313): Could not find method org.apache.http.client.methods.HttpRequestBase.releaseConnection, referenced from method com.mashape.unirest.http.HttpClientHelper.request
12-09 12:00:46.229: W/dalvikvm(1313): VFY: unable to resolve virtual method 2565: Lorg/apache/http/client/methods/HttpRequestBase;.releaseConnection ()V
12-09 12:00:46.229: D/dalvikvm(1313): VFY: replacing opcode 0x6e at 0x0012
12-09 12:00:46.239: I/dalvikvm(1313): Could not find method org.apache.http.client.methods.HttpRequestBase.releaseConnection, referenced from method com.mashape.unirest.http.HttpClientHelper.request
12-09 12:00:46.239: W/dalvikvm(1313): VFY: unable to resolve virtual method 2565: Lorg/apache/http/client/methods/HttpRequestBase;.releaseConnection ()V
12-09 12:00:46.239: D/dalvikvm(1313): VFY: replacing opcode 0x6e at 0x0021
12-09 12:00:46.269: I/dalvikvm(1313): Could not find method org.apache.http.conn.routing.HttpRoute.getLocalSocketAddress, referenced from method org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect
12-09 12:00:46.269: W/dalvikvm(1313): VFY: unable to resolve virtual method 3136: Lorg/apache/http/conn/routing/HttpRoute;.getLocalSocketAddress ()Ljava/net/InetSocketAddress;
12-09 12:00:46.269: D/dalvikvm(1313): VFY: replacing opcode 0x6e at 0x0020
12-09 12:00:46.379: D/dalvikvm(1313): DexOpt: couldn't find static field Lorg/apache/http/message/BasicLineFormatter;.INSTANCE
12-09 12:00:46.379: W/dalvikvm(1313): VFY: unable to resolve static field 2580 (INSTANCE) in Lorg/apache/http/message/BasicLineFormatter;
12-09 12:00:46.379: D/dalvikvm(1313): VFY: replacing opcode 0x62 at 0x0008
12-09 12:00:46.379: W/dalvikvm(1313): Exception Ljava/lang/NoSuchFieldError; thrown while initializing Lorg/apache/http/impl/io/DefaultHttpRequestWriterFactory;
12-09 12:00:46.389: W/dalvikvm(1313): Exception Ljava/lang/NoSuchFieldError; thrown while initializing Lorg/apache/http/impl/conn/ManagedHttpClientConnectionFactory;
12-09 12:00:46.389: W/dalvikvm(1313): Exception Ljava/lang/NoSuchFieldError; thrown while initializing Lcom/mashape/unirest/http/options/Options;
12-09 12:00:46.389: D/AndroidRuntime(1313): Shutting down VM
12-09 12:00:46.389: W/dalvikvm(1313): threadid=1: thread exiting with uncaught exception (group=0xb2a8cba8)
12-09 12:00:46.409: E/AndroidRuntime(1313): FATAL EXCEPTION: main
12-09 12:00:46.409: E/AndroidRuntime(1313): Process: your.company, PID: 1313
12-09 12:00:46.409: E/AndroidRuntime(1313): java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE
12-09 12:00:46.409: E/AndroidRuntime(1313):         at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:494)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:149)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:138)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:114)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:105)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at com.mashape.unirest.http.options.Options.refresh(Options.java:55)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at com.mashape.unirest.http.options.Options.<clinit>(Options.java:36)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:153)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:133)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at com.mashape.unirest.request.BaseRequest.asJson(BaseRequest.java:68)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at your.company.HelloAndroidActivity.onCreate(HelloAndroidActivity.java:28)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at android.app.Activity.performCreate(Activity.java:5231)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at android.app.ActivityThread.access$800(ActivityThread.java:135)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at android.os.Handler.dispatchMessage(Handler.java:102)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at android.os.Looper.loop(Looper.java:136)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at android.app.ActivityThread.main(ActivityThread.java:5017)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at java.lang.reflect.Method.invokeNative(Native Method)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at java.lang.reflect.Method.invoke(Method.java:515)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
12-09 12:00:46.409: E/AndroidRuntime(1313):         at dalvik.system.NativeStart.main(Native Method)
12-09 12:05:46.859: I/Process(1313): Sending signal. PID: 1313 SIG: 9
12-09 12:15:40.529: I/dalvikvm(1349): Could not find method org.apache.http.client.methods.HttpRequestBase.releaseConnection, referenced from method com.mashape.unirest.http.HttpClientHelper.request
12-09 12:15:40.529: W/dalvikvm(1349): VFY: unable to resolve virtual method 2565: Lorg/apache/http/client/methods/HttpRequestBase;.releaseConnection ()V
12-09 12:15:40.539: D/dalvikvm(1349): VFY: replacing opcode 0x6e at 0x0012
12-09 12:15:40.539: I/dalvikvm(1349): Could not find method org.apache.http.client.methods.HttpRequestBase.releaseConnection, referenced from method com.mashape.unirest.http.HttpClientHelper.request
12-09 12:15:40.539: W/dalvikvm(1349): VFY: unable to resolve virtual method 2565: Lorg/apache/http/client/methods/HttpRequestBase;.releaseConnection ()V
12-09 12:15:40.539: D/dalvikvm(1349): VFY: replacing opcode 0x6e at 0x0021
12-09 12:15:40.559: I/dalvikvm(1349): Could not find method org.apache.http.conn.routing.HttpRoute.getLocalSocketAddress, referenced from method org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect
12-09 12:15:40.559: W/dalvikvm(1349): VFY: unable to resolve virtual method 3136: Lorg/apache/http/conn/routing/HttpRoute;.getLocalSocketAddress ()Ljava/net/InetSocketAddress;
12-09 12:15:40.559: D/dalvikvm(1349): VFY: replacing opcode 0x6e at 0x0020
12-09 12:15:40.669: D/dalvikvm(1349): DexOpt: couldn't find static field Lorg/apache/http/message/BasicLineFormatter;.INSTANCE
12-09 12:15:40.669: W/dalvikvm(1349): VFY: unable to resolve static field 2580 (INSTANCE) in Lorg/apache/http/message/BasicLineFormatter;
12-09 12:15:40.669: D/dalvikvm(1349): VFY: replacing opcode 0x62 at 0x0008
12-09 12:15:40.679: W/dalvikvm(1349): Exception Ljava/lang/NoSuchFieldError; thrown while initializing Lorg/apache/http/impl/io/DefaultHttpRequestWriterFactory;
12-09 12:15:40.679: W/dalvikvm(1349): Exception Ljava/lang/NoSuchFieldError; thrown while initializing Lorg/apache/http/impl/conn/ManagedHttpClientConnectionFactory;
12-09 12:15:40.679: W/dalvikvm(1349): Exception Ljava/lang/NoSuchFieldError; thrown while initializing Lcom/mashape/unirest/http/options/Options;
12-09 12:15:40.679: D/AndroidRuntime(1349): Shutting down VM
12-09 12:15:40.689: W/dalvikvm(1349): threadid=1: thread exiting with uncaught exception (group=0xb2a8cba8)
12-09 12:15:40.719: E/AndroidRuntime(1349): FATAL EXCEPTION: main
12-09 12:15:40.719: E/AndroidRuntime(1349): Process: your.company, PID: 1349
12-09 12:15:40.719: E/AndroidRuntime(1349): java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE
12-09 12:15:40.719: E/AndroidRuntime(1349):         at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:494)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:149)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:138)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:114)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:105)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at com.mashape.unirest.http.options.Options.refresh(Options.java:55)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at com.mashape.unirest.http.options.Options.<clinit>(Options.java:36)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:153)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:133)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at com.mashape.unirest.request.BaseRequest.asJson(BaseRequest.java:68)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at your.company.HelloAndroidActivity.onCreate(HelloAndroidActivity.java:28)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at android.app.Activity.performCreate(Activity.java:5231)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at android.app.ActivityThread.access$800(ActivityThread.java:135)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at android.os.Handler.dispatchMessage(Handler.java:102)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at android.os.Looper.loop(Looper.java:136)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at android.app.ActivityThread.main(ActivityThread.java:5017)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at java.lang.reflect.Method.invokeNative(Native Method)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at java.lang.reflect.Method.invoke(Method.java:515)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
12-09 12:15:40.719: E/AndroidRuntime(1349):         at dalvik.system.NativeStart.main(Native Method)