无法在Android Studio

时间:2018-01-18 18:18:03

标签: android android-asynctask jsoup

我尝试使用此video

安装jsoup

然后,出现了一堆问题,一个接一个:

first thing

happened twice, for other files

fixed by ending java in task manager

fixed by clicking run after clean

解决了所有问题后,我尝试运行我的测试应用程序(这是我的MainActivity)

package babis.querytest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.IOException;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.i("qt","before");
    try {
        Log.i("qt","before1");
        Document doc= Jsoup.connect("http://www.google.com").get();
        Log.i("qt","after0");
    } catch (IOException e) {

    }
    Log.i("qt","after");
}
}

我的Logcat就是这个

  

01-18 20:05:38.758 17236-17236 /?我/艺术:延迟启用-Xcheck:jni   01-18 20:05:39.040 17236-17236 / babis.querytest W / art:失败的execv(/ system / bin / dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm64 --instruction-set-features = smp,a53 --runtime-arg -Xrelocate --boot-image = / system / framework / boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction- set-variant = generic --instruction-set-features = default --dex-file = / data / app / babis.querytest-1 / split_lib_dependencies_apk.apk --oat-file = / data / dalvik-cache / arm64 / data @ app @ babis.querytest-1 @ split_lib_dependencies_apk.apk @ classes.dex)因为非0退出状态   01-18 20:05:39.323 17236-17236 / babis.querytest W / art:失败的execv(/ system / bin / dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm64 --instruction-set-features = smp,a53 --runtime-arg -Xrelocate --boot-image = / system / framework / boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction- set-variant = generic --instruction-set-features = default --dex-file = / data / app / babis.querytest-1 / split_lib_slice_0_apk.apk --oat-file = / data / dalvik-cache / arm64 / data @ app @ babis.querytest-1 @ split_lib_slice_0_apk.apk @ classes.dex)因为非0退出状态   01-18 20:05:39.398 17236-17236 / babis.querytest W / art:失败的execv(/ system / bin / dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm64 --instruction-set-features = smp,a53 --runtime-arg -Xrelocate --boot-image = / system / framework / boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction- set-variant = generic --instruction-set-features = default --dex-file = / data / app / babis.querytest-1 / split_lib_slice_1_apk.apk --oat-file = / data / dalvik-cache / arm64 / data @ app @ babis.querytest-1 @ split_lib_slice_1_apk.apk @ classes.dex)因为非0退出状态   01-18 20:05:39.460 17236-17236 / babis.querytest W / art:失败的execv(/ system / bin / dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm64 --instruction-set-features = smp,a53 --runtime-arg -Xrelocate --boot-image = / system / framework / boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction- set-variant = generic --instruction-set-features = default --dex-file = / data / app / babis.querytest-1 / split_lib_slice_2_apk.apk --oat-file = / data / dalvik-cache / arm64 / data @ app @ babis.querytest-1 @ split_lib_slice_2_apk.apk @ classes.dex)因为非0退出状态   01-18 20:05:39.530 17236-17236 / babis.querytest W / art:失败的execv(/ system / bin / dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm64 --instruction-set-features = smp,a53 --runtime-arg -Xrelocate --boot-image = / system / framework / boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction- set-variant = generic --instruction-set-features = default --dex-file = / data / app / babis.querytest-1 / split_lib_slice_3_apk.apk --oat-file = / data / dalvik-cache / arm64 / data @ app @ babis.querytest-1 @ split_lib_slice_3_apk.apk @ classes.dex)因为非0退出状态   01-18 20:05:39.610 17236-17236 / babis.querytest W / art:失败的execv(/ system / bin / dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm64 --instruction-set-features = smp,a53 --runtime-arg -Xrelocate --boot-image = / system / framework / boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction- set-variant = generic --instruction-set-features = default --dex-file = / data / app / babis.querytest-1 / split_lib_slice_4_apk.apk --oat-file = / data / dalvik-cache / arm64 / data @ app @ babis.querytest-1 @ split_lib_slice_4_apk.apk @ classes.dex)因为非0退出状态   01-18 20:05:39.688 17236-17236 / babis.querytest W / art:失败的execv(/ system / bin / dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm64 --instruction-set-features = smp,a53 --runtime-arg -Xrelocate --boot-image = / system / framework / boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction- set-variant = generic --instruction-set-features = default --dex-file = / data / app / babis.querytest-1 / split_lib_slice_5_apk.apk --oat-file = / data / dalvik-cache / arm64 / data @ app @ babis.querytest-1 @ split_lib_slice_5_apk.apk @ classes.dex)因为非0退出状态   01-18 20:05:39.760 17236-17236 / babis.querytest W / art:失败的execv(/ system / bin / dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm64 --instruction-set-features = smp,a53 --runtime-arg -Xrelocate --boot-image = / system / framework / boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction- set-variant = generic --instruction-set-features = default --dex-file = / data / app / babis.querytest-1 / split_lib_slice_6_apk.apk --oat-file = / data / dalvik-cache / arm64 / data @ app @ babis.querytest-1 @ split_lib_slice_6_apk.apk @ classes.dex)因为非0退出状态   01-18 20:05:39.825 17236-17236 / babis.querytest W / art:失败的execv(/ system / bin / dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm64 --instruction-set-features = smp,a53 --runtime-arg -Xrelocate --boot-image = / system / framework / boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction- set-variant = generic --instruction-set-features = default --dex-file = / data / app / babis.querytest-1 / split_lib_slice_7_apk.apk --oat-file = / data / dalvik-cache / arm64 / data @ app @ babis.querytest-1 @ split_lib_slice_7_apk.apk @ classes.dex)因为非0退出状态   01-18 20:05:39.898 17236-17236 / babis.querytest W / art:失败的execv(/ system / bin / dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm64 --instruction-set-features = smp,a53 --runtime-arg -Xrelocate --boot-image = / system / framework / boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction- set-variant = generic --instruction-set-features = default --dex-file = / data / app / babis.querytest-1 / split_lib_slice_8_apk.apk --oat-file = / data / dalvik-cache / arm64 / data @ app @ babis.querytest-1 @ split_lib_slice_8_apk.apk @ classes.dex)因为非0退出状态   01-18 20:05:39.962 17236-17236 / babis.querytest W / art:失败的execv(/ system / bin / dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set = arm64 --instruction-set-features = smp,a53 --runtime-arg -Xrelocate --boot-image = / system / framework / boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction- set-variant = generic --instruction-set-features = default --dex-file = / data / app / babis.querytest-1 / split_lib_slice_9_apk.apk --oat-file = / data / dalvik-cache / arm64 / data @ app @ babis.querytest-1 @ split_lib_slice_9_apk.apk @ classes.dex)因为非0退出状态   01-18 20:05:39.964 17236-17236 / babis.querytest W / System:ClassLoader引用未知路径:/data/app/babis.querytest-1/lib/arm64   01-18 20:05:39.975 17236-17236 / babis.querytest I / InstantRun:启动即时运行服务器:是主进程   01-18 20:05:40.181 17236-17236 / babis.querytest W / art:在Android 4.1之前,方法android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter,android.content .res.ColorStateList,android.graphics.PorterDuff $ Mode)会错误地覆盖android.graphics.drawable.Drawable中的package-private方法   01-18 20:05:40.516 17236-17236 / babis.querytest I / qt:之前   01-18 20:05:40.516 17236-17236 / babis.querytest I / qt:before1   01-18 20:05:40.897 17236-17236 / babis.querytest I / Process:发送信号。 PID:17236 SIG:9

我的build.gradle就是这个

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "babis.querytest"
    minSdkVersion 23
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
packagingOptions {
    exclude 'META-INF/README.md'
    exclude 'META-INF/CHANGES'
}

}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation project(':jsoup-1.11.2')
compile 'org.jsoup:jsoup:1.11.2'

}

我的清单就是这样:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="babis.querytest">
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

应用程序在文档行崩溃。问题是什么?(wifi工作正常)

1 个答案:

答案 0 :(得分:1)

你必须在不在主线程上的异步任务中运行它

 new AsyncTask<Void, Void, Document>() {
            @Override
            protected Document doInBackground(Void... params) {
                Document doc= Jsoup.connect("http://www.google.com").get();
                return doc;
            }

            @Override
            protected void onPostExecute(Document document) {
                //parse docement here
            }
        }.execute((Void) null);