Rally Rest Api-Android应用程序 - 获取即使在导入所需的罐子后也找不到类

时间:2017-04-18 08:45:03

标签: java android http android-studio rally

我正在尝试建立一个拉力赛Android应用程序。我试过https://github.com/RallyTools/RallyRestToolkitForJava因为我已经添加了罐子。 1.commons编解码器-1.6.jar 2.gson-2.2.4.jar 3.httpclient-4.2.5.jar 4.org.apache.commons.logging-1.1.1.jar 5.httpcore-4.2.4.jar

我的mainActivity.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.request.QueryRequest;
import com.rallydev.rest.response.QueryResponse;

import org.apache.http.HttpHost;
import org.apache.http.client.utils.URIUtils;



    public class MainActivity extends AppCompatActivity
{
    String host = "https://rally1.rallydev.com";
String applicationName = "Android-Rally";
RallyRestApi restApi;
Button buttonlogin;
EditText etemail,etpass;
QueryRequest qtestset;
QueryResponse response;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    etemail=(EditText) findViewById(R.id.etemail);
    etpass=(EditText) findViewById(R.id.etpassword);
    buttonlogin=(Button) findViewById(R.id.btnlogin);
    buttonlogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v)
        {
            if(etemail.equals("") && etpass.equals(""))
            {
                Toast.makeText(getApplicationContext(),"Enter your Rally Credentials",Toast.LENGTH_LONG).show();
            }
            else
            {
                try
                {
                    getRally();
                }
                catch (URISyntaxException e)
                {
                    e.printStackTrace();
                }
                qtestset = new QueryRequest("Defects");
                qtestset.setLimit(1);
                try
                {
                    response = restApi.query(qtestset);
                    if(!response.wasSuccessful())
                    {
                        Toast.makeText(getApplicationContext(),"Login Un-Successful",Toast.LENGTH_LONG).show();


                    }
                    else{
                        Toast.makeText(getApplicationContext(),"Login Successful",Toast.LENGTH_LONG).show();
                    }
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }



            }


        }
    });

}

public RallyRestApi getRally() throws URISyntaxException {
    String password = etemail.getText().toString();
    String email=etpass.getText().toString();
    restApi = new RallyRestApi(new URI(host), email,password);
    restApi.setApplicationName(applicationName);
    return restApi;
}
}

我的错误日志

  

04-18 14:07:16.299 11364-11364 / com.example.apetkar.rally_poc D / AndroidRuntime:关闭VM   04-18 14:07:16.299 11364-11364 / com.example.apetkar.rally_poc E / AndroidRuntime:FATAL EXCEPTION:main                                                                                  处理:com.example.apetkar.rally_poc,PID:11364                                                                                  java.lang.NoSuchMethodError:没有静态方法extractHost(Ljava / net / URI;)Lorg / apache / http / HttpHost;在类Lorg / apache / http / client / utils / URIUtils中;或其超级类(&g。/ org.apache.http.client.utils.URIUtils'的声明出现在/system/framework/org.apache.http.legacy.boot.jar中)                                                                                      at org.apache.http.impl.client.DecompressingHttpClient.getHttpHost(DecompressingHttpClient.java:113)                                                                                      在org.apache.http.impl.client.DecompressingHttpClient.execute(DecompressingHttpClient.java:108)                                                                                      在com.rallydev.rest.client.HttpClient.executeRequest(HttpClient.java:157)                                                                                      在com.rallydev.rest.client.HttpClient.doRequest(HttpClient.java:145)                                                                                      在com.rallydev.rest.client.BasicAuthClient.doRequest(BasicAuthClient.java:56)                                                                                      在com.rallydev.rest.client.HttpClient.doGet(HttpClient.java:221)                                                                                      在com.rallydev.rest.RallyRestApi.query(RallyRestApi.java:172)                                                                                      at com.example.apetkar.rally_poc.MainActivity $ 1.onClick(MainActivity.java:64)                                                                                      在android.view.View.performClick(View.java:5198)                                                                                      在android.view.View $ PerformClick.run(View.java:21147)                                                                                      在android.os.Handler.handleCallback(Handler.java:739)                                                                                      在android.os.Handler.dispatchMessage(Handler.java:95)                                                                                      在android.os.Looper.loop(Looper.java:148)                                                                                      在android.app.ActivityThread.main(ActivityThread.java:5417)                                                                                      at java.lang.reflect.Method.invoke(Native Method)                                                                                      在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)                                                                                      在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

任何人都可以在这里帮忙..现在好几天......谢谢

2 个答案:

答案 0 :(得分:1)

android是否运行了一些特殊的移动版java?似乎4.2 http组件可能不兼容。我还没有机会深入研究它,但我想知道是否有更新的那些与android环境兼容的组件?您可以尝试分配RallyRestToolkitForJava存储库并在本地更新依赖关系,看看是否可以让它运行...

答案 1 :(得分:1)

与包含的Apache HTTP jar和原生Android使用的jar类存在类冲突。我通过分支Rally项目并用OKHttp替换Apache HTTP来消除冲突。我的更改是在github中的fork:https://github.com/rawslaw/RallyRestToolkitForJava