Я прошел все вопросы, связанные с этой аварией android.view.ViewRootImpl$CalledFromWrongThreadException:
, но все вопросы используют представления в doInBackground, которые вызывают исключение, но я получаю исключение, указывающее на метод onPostExecute, так как я знаю, что мы можем использовать представленияв методе onPostExecute AsyncTask
Вот журналы сбоев.
android.view.ViewRootImpl$CalledFromWrongThreadException:
at android.view.ViewRootImpl.checkThread (ViewRootImpl.java:7777)
at android.view.ViewRootImpl.doDie (ViewRootImpl.java:6723)
at android.view.ViewRootImpl.die (ViewRootImpl.java:6708)
at android.view.WindowManagerGlobal.removeViewLocked (WindowManagerGlobal.java:478)
at android.view.WindowManagerGlobal.removeView (WindowManagerGlobal.java:409)
at android.view.WindowManagerImpl.removeViewImmediate (WindowManagerImpl.java:124)
at android.app.Dialog.dismissDialog (Dialog.java:418)
at android.app.Dialog.dismiss (Dialog.java:401)
at com.b******.*********.*******.FacebookActivity$async.onPostExecute (FacebookActivity.java:173)
at com.b******.*********.*******.FacebookActivity$async.onPostExecute (FacebookActivity.java:2)
at android.os.AsyncTask.finish (AsyncTask.java:695)
at android.os.AsyncTask.-wrap1 (Unknown Source)
at android.os.AsyncTask$InternalHandler.handleMessage (AsyncTask.java:712)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:166)
at android.app.ActivityThread.main (ActivityThread.java:6861)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:450)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:936)
Вот метод onPostExecute AsyncTask, на который указывает это сбои
@Override
protected void onPostExecute(String output) {
super.onPostExecute(output);
HTML = output;
videosList.clear();
// check if no video than give nextTry to true
videosList = getRegexBackArray(xmlCharacterConverter(HTML), "\"(http([^\"]+)?\\.mp4([^\"]+)?)\"");
if(nextTry == 0 && videosList.size() == 0){
nextTry = 1;
runAsync(website , "get" , getUserAgent("Desktop"));
}else if(videosList.size() > 0){
nextTry = 0;
if(active){
if(MainActivity.counter != 10){
MainActivity.counter++;
}
mDialogAdvance();
}else{
mDialog = true;
}
}else {
if(!m3u8.isEmpty()) {
new FacebookActivity.asyncm3u8().execute(m3u8, "get", "");
}else{
if(progressDialog != null && progressDialog.isShowing()){
progressDialog.dismiss();
}
Toast.makeText(FacebookActivity.this , "We didn't found your videos. can you try other Link ?. " , Toast.LENGTH_LONG).show();
}
}
}
ВотКод doInBackground.
@Override
protected String doInBackground(String... params) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
StringBuilder response = new StringBuilder("");
BufferedReader reader;
HttpURLConnection urlConnection;
try {
URL url = new URL(params[0]);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod(params[1].toUpperCase());
urlConnection.setRequestProperty("User-Agent" , params[2]);
urlConnection.setUseCaches( false );
urlConnection.setInstanceFollowRedirects(true);
HttpURLConnection.setFollowRedirects(true);
boolean redirect = false;
int status = urlConnection.getResponseCode();
if (status != HttpURLConnection.HTTP_OK) {
if (status == HttpURLConnection.HTTP_MOVED_TEMP
|| status == HttpURLConnection.HTTP_MOVED_PERM
|| status == HttpURLConnection.HTTP_SEE_OTHER)
redirect = true;
}
if (redirect) {
String newUrl = urlConnection.getHeaderField("Location");
urlConnection = (HttpURLConnection) new URL(newUrl).openConnection();
urlConnection.setRequestMethod(params[1].toUpperCase());
urlConnection.setReadTimeout(5500);
urlConnection.setConnectTimeout(5500);
urlConnection.setRequestProperty("User-Agent" , "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");
urlConnection.setUseCaches( false );
urlConnection.setInstanceFollowRedirects(true);
HttpURLConnection.setFollowRedirects(true);
}
try {
reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
while ((line = reader.readLine()) != null)
{
response.append(line).append("\n");
}
reader.close();
}catch(Exception j){
return "";
} finally {
urlConnection.disconnect();
}
}catch (IOException e) {
e.printStackTrace();
}
return response.toString();
}
}
Любая помощь будет высоко оценена.