2016-09-04 7 views
0

こんにちは、私はログイン画面を設定しようとしています。私はログイン確認のためにウェブサービスを使用しています。 Webサービスはローカルマシン上で実行されており、ログインが成功するとユーザーIDで応答するはずです。現在のところ、アプリケーションにはすべての権限があり、マニフェストの問題ではありません。http postでAndroidアプリケーションがクラッシュするokhttpで送信

私はokhttp:3.4.1を使用しています。

これは、loginメソッドをトリガーボタン

btnLogin.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     { 
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() 
        .permitAll().build(); 
      StrictMode.setThreadPolicy(policy); 
      //Intent mainMenu = new Intent(LoginActivity.this, MainMenu.class); 
      //LoginActivity.this.startActivity(mainMenu); 

      LoginImpl li = new LoginImpl(); 
      int userID = li.login(txtUsername.getText().toString(), txtPassword.getText().toString()); 

      new AlertDialog.Builder(LoginActivity.this) 
        .setTitle("TEST") 
        .setMessage("USER ID = " + userID) 
        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 

         } 
        }) 
        .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 

         } 
        }) 
        .setIcon(android.R.drawable.ic_dialog_alert) 
        .show(); 
     } 

    } 
}); 

これはログインが使用されたときに呼び出されるクラスである:

package diplomski.thop.thopmobileclient.controller.requests; 
import java.io.IOException; 
import com.google.gson.Gson; 
import diplomski.thop.thopmobileclient.controller.implementation.Urls; 
import diplomski.thop.thopmobileclient.model.User; 
import okhttp3.OkHttpClient; 
import okhttp3.Request; 
import okhttp3.RequestBody; 
import okhttp3.Response; 

public class LoginRequest { 

    OkHttpClient client; 

    public LoginRequest() { 
     client = new OkHttpClient(); 
    } 

    public int sendLoginRequest(String username, String password) { 
     User user = new User(username, password); 
     String requestJson = new Gson().toJson(user); 
     RequestBody body = RequestBody.create(Urls.JSON, requestJson); 
     Request request = new Request.Builder().url(Urls.LOGIN_URL).post(body).build(); 
     try (Response response = client.newCall(request).execute()) { 
      String returnResponse = response.body().string(); 
      if (returnResponse.equalsIgnoreCase("Fail")) { 
       return -1; 
      } else { 
       return Integer.parseInt(returnResponse); 
      } 
     } catch (IOException e) { 
      e.printStackTrace(); 
      return -1; 
     } 
    } 

} 

これは、使用してURLのイムです:

public static final String START_URL = "http://10.0.2.2:8080/ThopWebService/rest/"; 
public static final String LOGIN_URL = START_URL + "user/login"; 

Webサービスがローカルホスト上で実行されていて、エミュレータを使用しているため、私はt hat ip。

ログインをクリックするたびにtry (Response response = client.newCall(request).execute())になり、次のクラッシュメッセージが表示されます。

09-04 08:12:30.855 21873-21873/diplomski.thop.thopmobileclient E/AndroidRuntime: FATAL EXCEPTION: main Process: diplomski.thop.thopmobileclient, PID: 21873 java.lang.VerifyError: okhttp3/internal/http/Http1xStream$FixedLengthSink at okhttp3.internal.http.Http1xStream.newFixedLengthSink(Http1xStream.java:226) at okhttp3.internal.http.Http1xStream.createRequestBody(Http1xStream.java:98) at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:45) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
at okhttp3.RealCall.execute(RealCall.java:60) at diplomski.thop.thopmobileclient.controller.requests.LoginRequest.sendLoginRequest(LoginRequest.java:28) at diplomski.thop.thopmobileclient.controller.implementation.LoginImpl.login(LoginImpl.java:12) at diplomski.thop.thopmobileclient.LoginActivity$1.onClick(LoginActivity.java:37) at android.view.View.performClick(View.java:4438) at android.view.View$PerformClick.run(View.java:18422) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) 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:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)

私はアンドロイドの経験が非常に限られているため、これを修正する方法はわかりません。エラーを検出して解決策を見つけることができませんでした。

編集:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 24 
    buildToolsVersion "24.0.2" 

    defaultConfig { 
     applicationId "diplomski.thop.thopmobileclient" 
     minSdkVersion 19 
     targetSdkVersion 24 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:24.2.0' 
    compile 'com.android.volley:volley:1.0.0' 
    compile group: 'com.google.code.gson', name: 'gson', version: '2.6.2' 
    compile 'com.squareup.okhttp3:okhttp:3.4.1' 
} 

答えて

1

あなたはジャックでコンパイルしている私のbuild.gradleを追加しますか? Jack(https://code.google.com/p/android/issues/detail?id=82691)を使用している場合、Squareライブラリ(okhttp、picasso)がVerifyErrorを発生させていることがわかります。

モジュールレベルのビルドファイルを確認し、ジャックが有効になっているかどうかを確認してください。このようなもの:

jackOptions { 
    enabled true 
    } 
+0

デフォルトで有効になっていない限り、私は使っていないと思います。私はbuild.gradleを質問に含めました。私はそれにjackOptionsを追加する必要がありますか? – InsaneCricket

+0

jackOptionを追加したとき、エラーはなくなりました。ありがとうございました。 – InsaneCricket

+0

うん...ネマ問題。ユーザーはジャックが問題を引き起こしていると報告しました。しかし、私はあなたのエラーがなくなってうれしいです;) – Gudin

関連する問題