使用事实

时间:2016-03-09 09:18:23

标签: android android-studio verifyerror factual

您好我正在使用factual api在android studio中开发一个应用程序来查找餐馆。主要活动的代码是这个(我有钥匙,我现在只用xxx替换)

public class MainActivity extends Activity {

protected Factual factual = new Factual("xxx", "xxx");
private TextView resultText = null;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    double latitude = 34.06018;
    double longitude = -118.41835;
    int meters = 500;
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    String locationProvider = LocationManager.GPS_PROVIDER;

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    Location location = locationManager.getLastKnownLocation(locationProvider);
    if (location != null) {
        latitude = location.getLatitude();
        longitude = location.getLongitude();
    }

    Query query = new Query()
            .within(new Circle(latitude, longitude, meters))
            .field("cuisine").equal("Italian")
            .sortAsc("$distance")
            .only("name", "address", "tel");

    ReadResponse italian = factual.fetch("restaurants-us", query);

    for (Map restaurant : italian.getData()) {
        String name = (String) restaurant.get("name");
        String address = (String) restaurant.get("address");
        String phone = (String) restaurant.get("tel");
        Number distance = (Number) restaurant.get("$distance");
        System.out.println(distance + " meters away: " + name + " @ " + address + ", call " + phone);
    }


}

这是清单文件

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

这是gradle文件

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.example.hp.restaurants"
    minSdkVersion 8
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {

compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.google.guava:guava:17.0'
compile 'com.google.api-client:google-api-client:1.15.0-rc'
compile 'org.codehaus.jackson:jackson-core-asl:1.9.12'
compile 'commons-io:commons-io:2.4'
compile 'org.json:json:20131018'
compile 'junit:junit:4.12'
compile 'org.yaml:snakeyaml:1.12'

}

当我在我的物理Android设备中调试应用程序时,应用程序崩溃,我有以下错误:

FATAL EXCEPTION: main
Process: com.example.hp.restaurants, PID: 2476
java.lang.VerifyError: com/factual/driver/JsonUtil
at com.factual.driver.FieldFilter.toJsonStr(FieldFilter.java:28)
at com.factual.driver.Parameters$FilterList.toString(Parameters.java:155)
at java.lang.String.valueOf(String.java:1682)
at com.factual.driver.Parameters$SimpleData.toString(Parameters.java:226)
at java.lang.String.valueOf(String.java:1682)
at com.factual.driver.Parameters.toUrlParams(Parameters.java:72)
at com.factual.driver.Query.toUrlParams(Query.java:285)
at com.factual.driver.Factual.fetch(Factual.java:114)
at com.example.hp.restaurants.MainActivity.onCreate(MainActivity.java:63)
at android.app.Activity.performCreate(Activity.java:5619)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2607)
at android.app.ActivityThread.access$900(ActivityThread.java:174)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1325)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5756)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)

错误的一行是这样的:

ReadResponse italian = factual.fetch("restaurants-us", query);

0 个答案:

没有答案