2017-01-05 2 views
-2

나는 내 데이터베이스에 데이터를 게시하는 안드로이드 애플 리케이션을 작성했습니다. 앱은 데이터를 데이터베이스에 게시하는 웹 서비스에 액세스해야합니다. webservice 잘 작동합니다. 내 브라우저에서 테스트 해 본다면 이미 서버에 있습니다. 지금은 내 애플 리케이션 webservice를 실행하고 싶습니다. 하지만 그 doesnt 일. 내 디버거가 작동하지 않으므로 디버깅 할 수 없습니다. 여기 내 코드 webservice에 액세스하는 것입니다. 어떤 아이디어? 클래스가HTTP 요청에서 응답 없음

new PostBlog(insertBlogURL).execute(""); 

에 의해 내 주요 활동에서 호출

public class PostBlog extends AsyncTask<String, Void, String> { 
String BlogURL; 

public PostBlog(String insertBlogURL) { 
    BlogURL = insertBlogURL; 
} 

@Override 
protected String doInBackground(String... params) { 
    postBlogData(BlogURL); 
    return null; 
} 

public void postBlogData(String url) { 

    String result = ""; 
    //the year data to send 
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 
    nameValuePairs.add(new BasicNameValuePair("year", "1980")); 

    //http post 
    try { 
     HttpClient httpclient = new DefaultHttpClient(); 
     HttpPost httppost = new HttpPost(url); 
     httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
     HttpResponse response = httpclient.execute(httppost); 
     HttpEntity entity = response.getEntity(); 
     InputStream is = entity.getContent(); 
     BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); 
     StringBuilder sb = new StringBuilder(); 
     String line = null; 
     while ((line = reader.readLine()) != null) { 
      sb.append(line + "\n"); 
     } 
     is.close(); 

     result = sb.toString(); 
    } catch (Exception e) { 

     //(TextView)rootView.findViewById(R.id.question) 
     Log.e("log_tag", "Error converting result " + e.toString()); 
    } 


} 

}는 서버에 내 ".jsp로? asdd = sdsd"파일을 실행하는 또 다른 쉬운 방법이 있습니까?

의견을 보내 주셔서 감사합니다.

+1

앱을 디버그 할 수없는 경우 로그 만 추가하면됩니다. 그리고 로그가 말하는 것을 말해주십시오. – deathangel908

+0

로그를 추가하는 방법 및 위치는 어디입니까? – theAlgorithmGod

+1

https://developer.android.com/reference/android/util/Log.html 결과가 무엇인지 알 수없는 모든 행이 나온 후에. 그리고 만약 당신이 안드로이드를 공부하고 있다면 디버거와 잘 지내야합니다. stackoverflow에 질문을 게시하면 문제가 무엇인지 이해할 수없는 경우 도움이되지 않습니다. – deathangel908

답변

0
대신 일을

:

new PostBlog(insertBlogURL).execute("");

변경 생성자 및

params[0]을 수행하여 doInBackground 방법에서 URL을 검색 그런 다음이

PostBlog blogPoster = new PostBlog(); 
try { 
    blogPoster.execute(insertBlogURL); 
} catch (InterruptedException e) {} catch (ExecutionException e) {} 

I 등의 다운로드를 시작 이 코드는 내 프로젝트의 수정 된 코드 조각이라고해야합니다. rk 정확히 당신이 기대하는 방식.

+0

변경된 생성자를 어떻게 표시해야할까요? 왜 1 번의 시도에 2 가지 예외를 추가합니까? 컴파일러가 오류 4를 표시합니다. 감사합니다. – theAlgorithmGod

+0

@theAlgorithmGod는 생성자를 모두 삭제합니다. 필요하지 않습니다. 'postBlogData' 메쏘드에'BlogURL'을 건네주는 대신 doInBackground에서'params [0]' – sketch204

+0

@theAlgorithmGod를 전달합니다. 정확하게 두 가지 오류를 잡아냅니다. 물론 일반적인 'Exception'을 잡을 수는 있습니다. 당신은 정확히 어떤 에러가 발생했는지 알 수 없다. 컴파일러 에러를 많이 알지 못해서 나는 당신을 도울 수 없다. – sketch204

관련 문제