2015-02-04 6 views
1

OpenHab 서버에 대한 안드로이드 클라이언트를 wAsync를 사용하여 작성하려고했습니다.wAsync throw ClassNotFondException

내가 SDK 버전과 안드로이드 스튜디오를 사용하고 21

내 코드 : 인터넷 및 액세스 네트워크 상태에 대한

import android.os.StrictMode; 
import android.support.v7.app.ActionBarActivity; 
import android.os.Bundle; 
import android.util.Log; 

import android.view.View; 
import android.widget.Button; 

import android.widget.TextView; 

import org.atmosphere.wasync.ClientFactory; 
import org.atmosphere.wasync.Decoder; 
import org.atmosphere.wasync.Encoder; 
import org.atmosphere.wasync.Event; 
import org.atmosphere.wasync.Function; 
import org.atmosphere.wasync.Request; 
import org.atmosphere.wasync.RequestBuilder; 
import org.atmosphere.wasync.Socket; 
import org.atmosphere.wasync.impl.AtmosphereClient; 
import org.codehaus.jackson.map.ObjectMapper; 

import android.os.Handler; 

import java.io.IOException; 


public class MainActivity extends ActionBarActivity { 

private Button act; 
private TextView view; 
private final String serverIp="http://demo.openhab.org:8080/rest/items/DemoSwitch/state"; 
private final static ObjectMapper mapper=new ObjectMapper(); 
private final Handler uiHandler=new Handler(); 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
    StrictMode.setThreadPolicy(policy); 

    setContentView(R.layout.activity_main); 

    act = (Button) findViewById(R.id.act); 
    view = (TextView) findViewById(R.id.view); 


     AtmosphereClient client = ClientFactory.getDefault().newClient(AtmosphereClient.class); 

     RequestBuilder request = client.newRequestBuilder() 
       .method(Request.METHOD.GET) 
       .uri(serverIp) 
       .trackMessageLength(true) 
       .encoder(new Encoder<State, String>() { 
        @Override 
        public String encode(State data) { 
         try { 
          return mapper.writeValueAsString(data); 
         } catch (IOException e) { 
          throw new RuntimeException(e); 
         } 
        } 
       }) 
       .decoder(new Decoder<String, State>() { 
        @Override 
        public State decode(Event type, String data) { 

         data = data.trim(); 

         // Padding 
         if (data.length() == 0) { 
          return null; 
         } 

         if (type.equals(Event.MESSAGE)) { 
          try { 
           return mapper.readValue(data, State.class); 
          } catch (IOException e) { 
           e.printStackTrace(); 
           return null; 
          } 
         } else { 
          return null; 
         } 
        } 
       }) 
       .transport(Request.TRANSPORT.LONG_POLLING); 

     final Socket socket = client.create(); 
    try { 
     socket.on("message", new Function<State>() { 
      @Override 
      public void on(final State t) { 
       uiHandler.post(new Runnable() { 
        @Override 
        public void run() { 

         view.append("State " + t.getState()); 
        } 
       }); 
      } 
     }).on(new Function<Throwable>() { 

      @Override 
      public void on(Throwable t) { 
       view.setText("ERROR 3: " + t.getMessage()); 
       t.printStackTrace(); 
      } 

     }).open(request.build()); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    act.setOnClickListener(new View.OnClickListener() { 



      public void onClick(View v) { 
       try { 

        socket.fire(new State("ON")); 

        Log.d("Client", "Client sent message"); 
       } catch (Throwable e) { 
        view.setText("ERROR 3: " + e.getMessage()); 
        e.printStackTrace(); 
       } 
      } 
     }); 


} 



} 

내가 추가 한 permmissions.

은 메이븐 센트럴에서 종속성 wasync-2.0.0-all을 추가했습니다.

하지만 연결이 성공하지 못했습니다. 내가 얻는 오류는 다음과 같습니다.

Caused by: java.lang.ClassNotFoundException: Didn't find class "sun.security.util.HostnameChecker" on path: DexPathList[[zip file "/data/app/com.att_lnx_admin.atmosphereclient-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.att_lnx_admin.atmosphereclient-1, /system/lib]] 

누군가 제발 도와주세요.

답변

1

서버 쪽이 최신 버전이 아닌 것 같습니다. Android 측에서 이전 버전 사용 : compile 'org.atmosphere : wasync : 1.4.3'

0

문제는 AHC 라이브러리와 관련이 있습니다. 새로운 릴리스가 이번 주에 완료되므로 async-http-client를 1.9.9로 업데이트하면됩니다.

-1

EDIT : 새롭게 출시 된 1.9.10 버전을 사용하여 해결되었습니다. 여기에 최종 작업 build.gradle은 다음과 같습니다

compile ('com.ning:async-http-client:1.9.10') 
    compile ('org.atmosphere:wasync:2.0.0') { 
     exclude group: 'com.ning', module: 'async-http-client' 
    } 

감사 비동기 HHTP 클라이언트 1.9.9가 릴리스되었습니다 https://github.com/AsyncHttpClient/async-http-client/tree/async-http-client-1.9.10


오늘 wasync 및 비동기 HTTP 클라이언트 제작자. 내 안드로이드 build.gradle 파일이 시도했습니다 :

compile ('com.ning:async-http-client:1.9.9') 
compile ('org.atmosphere:wasync:2.0.0') { 
    exclude group: 'com.ning', module: 'async-http-client' 
} 

과 sun.security.util.HostnameChecker NoClassDefFoundError를 사라,하지만 난 소켓 연결을 할 때 다른 오류가 있습니다

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/ning/http/client/providers/netty/NettyAsyncHttpProviderConfig; 
      at org.atmosphere.wasync.impl.ClientUtil.createDefaultAsyncHttpClient(ClientUtil.java:35) 
      at org.atmosphere.wasync.impl.ClientUtil.create(ClientUtil.java:74) 
      at org.atmosphere.wasync.impl.AtmosphereClient.create(AtmosphereClient.java:41)