简体   繁体   中英

Error when trying to implement amazon mturk SDK into android studio project

I am trying to implement Amazon's mechanical turk into my android app. I have followed the instructions: http://docs.aws.amazon.com/AWSMechTurk/latest/AWSMechanicalTurkGettingStartedGuide/CreatingAHIT.html#Java but when I am specifying the third party .jar files, it gives me

Error:Gradle: Execution failed for task ':app:dexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

I have tried taking out every combination of .jar files and found out that jaxrpc.jar is the file causing this error. Without this file, the error when running the project is:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException
    at com.example.mturk.HomeworkRequest.<init>(HomeworkRequest.java:20)
    at com.example.mturk.HomeworkRequest.main(HomeworkRequest.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at ...

where line 20 points to:

service = new RequesterService(new PropertiesClientConfig("../mturk.properties"));

and line 39 points to:

HomeworkRequest app = new HomeworkRequest();

I have tried enabling multiDex and looked around but couldn't find any solution. Any help would be greatly appreciated, I have been stuck on this problem for a few days now.

EDIT: Here's my code so far. It's just a simple HIT request similar to the sample in http://docs.aws.amazon.com/AWSMechTurk/latest/AWSMechanicalTurkGettingStartedGuide/CreatingAHIT.html#Java

import com.amazonaws.mturk.requester.HIT;
import com.amazonaws.mturk.service.axis.RequesterService;
import com.amazonaws.mturk.service.exception.ServiceException;
import com.amazonaws.mturk.util.PropertiesClientConfig;

public class HomeworkRequest{

private RequesterService service;
private String title= "Math Question";
private String description = "Solve the math question shown";
private int numAssignments = 3;
private double reward = 0.05;

public HomeworkRequest(){
    service = new RequesterService(new PropertiesClientConfig("../mturk.properties"));
}

public void createHomeworkRequest(){
    try {
        HIT hit = service.createHIT(
                title, description, reward, RequesterService.getBasicFreeTextQuestion(
                        "Can you solve this math question?"), numAssignments);

        System.out.println("Created HIT: " + hit.getHITId());
        System.out.println("HIT location: ");
        System.out.println(service.getWebsiteURL() + "/mturk/preview?groupId=" + hit.getHITTypeId());
    }
    catch(ServiceException e) {
        System.err.println(e.getLocalizedMessage());
    }
}

public static void main(String[] args){
    HomeworkRequest app = new HomeworkRequest();
    app.createHomeworkRequest();
}
}

If you look at step 1 of using the MTurk Java SDK, you need to include SDK Installation Directory]\\lib\\third-party in your classpath .

Your inability to find third-party jars such as JaxB seems to suggest that your IDE is facing issues finding necessary jars to build.

Please let us know if you are still facing difficulties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM