android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a vi
3681 단어 android실행 오류 및 해결 방법
, 다음 오류를 보고했습니다.
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
대체적으로, 나는 비주선 라인에서 ui를 업데이트해서 붕괴되었다
(정말 저급한 실수다. 작년에 저지른 실수를 올해도 저질렀다)
private void setdate() {
new Thread(new Runnable() {
@Override
public void run() {
String strURL = "http://jirenguapi.applinzi.com/weather.php";
URL url = null;
try {
url = new URL(strURL);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
InputStreamReader input = new InputStreamReader(httpConn
.getInputStream(), "utf-8");
BufferedReader bufReader = new BufferedReader(input);
String line = "";
StringBuilder contentBuf = new StringBuilder();
while ((line = bufReader.readLine()) != null) {
contentBuf.append(line);
}
date_weather.setText(contentBuf);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
, handler , , handler, ui
private Handler
handler_setdate = new Handler()
{
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
String message = msg.obj.toString();
date_weather.setText(message);
}
};
private void setdate() {
new Thread(new Runnable() {
@Override
public void run() {
String strURL = "http://jirenguapi.applinzi.com/weather.php";
URL url = null;
try {
url = new URL(strURL);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
InputStreamReader input = new InputStreamReader(httpConn
.getInputStream(), "utf-8");
BufferedReader bufReader = new BufferedReader(input);
String line = "";
StringBuilder contentBuf = new StringBuilder();
while ((line = bufReader.readLine()) != null) {
contentBuf.append(line);
}
Message msg = new Message();
msg.obj= contentBuf;
handler_setdate.sendMessage(msg);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.