我看了来自android教程系列的教程视频。在此视频中,该家伙编写了“ AsyncTask”类的新类扩展,然后从网站下载了页面源代码。我写了那个代码,但是没用! 我尝试使用http和https连接以及网站,但仍然无法使用
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DownloadTask task = new DownloadTask();
String result = null;
try {
result = task.execute("https://www.google.com").get();
Log.i("result",result);
}
catch (Exception e){
Log.i("Error " , "in main activity");
}
}
public void clickedFunc(View view){
}
public class DownloadTask extends AsyncTask<String , Void , String>{
@Override
protected String doInBackground(String... strings) {
String result = "" ;
URL url ;
HttpsURLConnection httpsURLConnection = null ;
try{
url = new URL(strings[0]);
httpsURLConnection = (HttpsURLConnection)url.openConnection();
InputStream inputStream = httpsURLConnection.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
int data = inputStreamReader.read();
while (data != -1){
char current = (char) data ;
result += current ;
data = inputStream.read();
}
return result ;
}catch (Exception e){
Log.i("Error " , "in async class");
}
return null;
}
}
}
主要日志是:
W / art:execv失败
I/Choreographer: Skipped 112 frames! The application may be doing too much work on its main thread.
.
.
.
All my logs :
W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=x86 --instruction-set-features=smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=x86 --instruction-set-features=default --dex-file=/data/app/com.sadghostgame.myproject2-2/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/x86/data@app@com.sadghostgame.myproject2-2@split_lib_dependencies_apk.apk@classes.dex) because non-0 exit status
W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=x86 --instruction-set-features=smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=x86 --instruction-set-features=default --dex-file=/data/app/com.sadghostgame.myproject2-2/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/x86/data@app@com.sadghostgame.myproject2-2@split_lib_slice_0_apk.apk@classes.dex) because non-0 exit status
W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=x86 --instruction-set-features=smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=x86 --instruction-set-features=default --dex-file=/data/app/com.sadghostgame.myproject2-2/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/x86/data@app@com.sadghostgame.myproject2-2@split_lib_slice_1_apk.apk@classes.dex) because non-0 exit status
W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=x86 --instruction-set-features=smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=x86 --instruction-set-features=default --dex-file=/data/app/com.sadghostgame.myproject2-2/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/x86/data@app@com.sadghostgame.myproject2-2@split_lib_slice_2_apk.apk@classes.dex) because non-0 exit status
W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=x86 --instruction-set-features=smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=x86 --instruction-set-features=default --dex-file=/data/app/com.sadghostgame.myproject2-2/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/x86/data@app@com.sadghostgame.myproject2-2@split_lib_slice_3_apk.apk@classes.dex) because non-0 exit status
W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=x86 --instruction-set-features=smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=x86 --instruction-set-features=default --dex-file=/data/app/com.sadghostgame.myproject2-2/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/x86/data@app@com.sadghostgame.myproject2-2@split_lib_slice_4_apk.apk@classes.dex) because non-0 exit status
W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=x86 --instruction-set-features=smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=x86 --instruction-set-features=default --dex-file=/data/app/com.sadghostgame.myproject2-2/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/x86/data@app@com.sadghostgame.myproject2-2@split_lib_slice_5_apk.apk@classes.dex) because non-0 exit status
W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=x86 --instruction-set-features=smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=x86 --instruction-set-features=default --dex-file=/data/app/com.sadghostgame.myproject2-2/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/x86/data@app@com.sadghostgame.myproject2-2@split_lib_slice_6_apk.apk@classes.dex) because non-0 exit status
W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=x86 --instruction-set-features=smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=x86 --instruction-set-features=default --dex-file=/data/app/com.sadghostgame.myproject2-2/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/x86/data@app@com.sadghostgame.myproject2-2@split_lib_slice_7_apk.apk@classes.dex) because non-0 exit status
W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=x86 --instruction-set-features=smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=x86 --instruction-set-features=default --dex-file=/data/app/com.sadghostgame.myproject2-2/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/x86/data@app@com.sadghostgame.myproject2-2@split_lib_slice_8_apk.apk@classes.dex) because non-0 exit status
W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable --instruction-set=x86 --instruction-set-features=smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=x86 --instruction-set-features=default --dex-file=/data/app/com.sadghostgame.myproject2-2/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/x86/data@app@com.sadghostgame.myproject2-2@split_lib_slice_9_apk.apk@classes.dex) because non-0 exit status
W/System: ClassLoader referenced unknown path: /data/app/com.sadghostgame.myproject2-2/lib/x86
I/InstantRun: starting instant run server: is main process
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
I/art: Background sticky concurrent mark sweep GC freed 1906(11MB) AllocSpace objects, 476(7MB) LOS objects, 54% free, 3MB/7MB, paused 1.567ms total 101.035ms
I/art: Background partial concurrent mark sweep GC freed 985(5MB) AllocSpace objects, 245(4MB) LOS objects, 39% free, 5MB/8MB, paused 1.391ms total 113.434ms
I/art: Background partial concurrent mark sweep GC freed 304(11KB) AllocSpace objects, 451(7MB) LOS objects, 39% free, 2MB/3MB, paused 894us total 123.406ms
I/art: Background partial concurrent mark sweep GC freed 187(7KB) AllocSpace objects, 276(5MB) LOS objects, 39% free, 3MB/5MB, paused 1.510ms total 106.619ms
I/art: Background partial concurrent mark sweep GC freed 262(10KB) AllocSpace objects, 387(7MB) LOS objects, 39% free, 4MB/7MB, paused 849us total 179.700ms
I/art: Background partial concurrent mark sweep GC freed 335(13KB) AllocSpace objects, 498(9MB) LOS objects, 39% free, 4MB/7MB, paused 986us total 153.366ms
I/art: Background partial concurrent mark sweep GC freed 220(8KB) AllocSpace objects, 320(5MB) LOS objects, 40% free, 4MB/7MB, paused 885us total 145.691ms
I/art: Background sticky concurrent mark sweep GC freed 333(13KB) AllocSpace objects, 495(10MB) LOS objects, 64% free, 2MB/6MB, paused 917us total 112.418ms
I/art: Background partial concurrent mark sweep GC freed 124(4KB) AllocSpace objects, 181(4MB) LOS objects, 39% free, 5MB/9MB, paused 870us total 110.436ms
I/art: Background partial concurrent mark sweep GC freed 268(10KB) AllocSpace objects, 394(8MB) LOS objects, 40% free, 4MB/7MB, paused 846us total 194.871ms
I/art: Background partial concurrent mark sweep GC freed 245(9KB) AllocSpace objects, 359(7MB) LOS objects, 39% free, 3MB/5MB, paused 872us total 135.049ms
I/art: Background partial concurrent mark sweep GC freed 209(8KB) AllocSpace objects, 310(7MB) LOS objects, 39% free, 4MB/7MB, paused 964us total 116.422ms
I/art: Background partial concurrent mark sweep GC freed 125(4KB) AllocSpace objects, 184(29MB) LOS objects, 39% free, 5MB/8MB, paused 1.642ms total 100.880ms
I/art: Background partial concurrent mark sweep GC freed 34(1312B) AllocSpace objects, 43(7MB) LOS objects, 40% free, 4MB/8MB, paused 7.004ms total 121.774ms
I/art: Background partial concurrent mark sweep GC freed 36(1360B) AllocSpace objects, 50(8MB) LOS objects, 39% free, 2MB/3MB, paused 6.189ms total 64.339ms
I/art: Background partial concurrent mark sweep GC freed 22(784B) AllocSpace objects, 31(5MB) LOS objects, 40% free, 2MB/4MB, paused 7.244ms total 39.136ms
I/art: Background partial concurrent mark sweep GC freed 82(3KB) AllocSpace objects, 114(20MB) LOS objects, 39% free, 4MB/8MB, paused 896us total 136.579ms
I/art: Background partial concurrent mark sweep GC freed 81(3KB) AllocSpace objects, 114(28MB) LOS objects, 39% free, 5MB/9MB, paused 881us total 117.422ms
I/result: <||google.kEI};google.getLEI=function(a){for(var b=null;a&&(!a.getAttribute||!(b=a.getAttribute("leid")));)a=a.parentNode;return b};google.https=function(){return"https:"==window.location.protocol};google.ml=function(){return null};google.log=function(a,b,e,c,g){if(a=google.logUrl(a,b,e,c,g)){b=new Image;var d=google.lc,f=google.li;d[f]=b;b.onerror=b.onload=b.onabort=function(){delete d[f]};google.vel&&google.vel.lu&&google.vel.lu(a);b.src=a;google.li=f+1}};google.logUrl=function(a,b,e,c,g){var d="",f=google.ls||"";e||-1!=b.search("&ei=")||(d="&ei="+google.getEI(c),-1==b.search("&lei=")&&(c=google.getLEI(c))&&(d+="&lei="+c));c="";!e&&google.cshid&&-1==b.search("&cshid=")&&"slh"!=a&&(c="&cshid="+google.cshid);a=e||"/"+(g||"gen_204")+"?atyp=i&ct="+a+"&cad="+b+d+f+"&zx="+google.time()+c;/^http:/i.test(a)&&google.https()&&(google.ml(Error("a"),!1,{src:a,glmm:1}),a="");return a};}).call(this);(function(){google.y={};google.x=function(a,b){if(a)var c=a.id;else{do c=Math.random();while(google.y[c])}google.y[c]=[a,b];return!1};google.lm=[];google.plm=function(a){google.lm.push.apply(google.lm,a)};google.lq=[];google.load=function(a,b,c){google.lq.push([[a],b,c])};google.loadAll=function(a,b){google.lq.push([a,b])};}).call(this);google.f={};(function(){google.hs={h:true};})();(function(){google.c={c:{a:true,m:false,n:false,p:false,wi:true}};google.sn='webhp';(function(){var e=function(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent&&a.attachEvent("on"+b,c)};google.tick=function(a,b,c){google.timers[a]||google.startTick(a);c=void 0!==c?c:google.time();b instanceof Array||(b=[b]);for(var d=0;d<b.length;++d)google.timers[a].t[b[d].clearcut]={key:b[d],ts:c}};google.c.e=function(a,b,c){google.timers[a].e[b]=c};google.c.b=function(a){var b=google.timers.load.m;b[a]&&google.ml(Error("a"),!1,{m:a});b[a]=!0};google.c.u=function(a){var b=google.timers.load.m;if(b[a]){b[a]=!1;for(a in b)if(b[a])return;google.csiReport()}else google.ml(Error("b"),!1,{m:a})};google.rll=function(a,b,c){var d=function(b){c(b);b=d;a.addEventListener?a.removeEventListener("load",b,!1):a.attachEvent&&a.detachEvent("onload",b);b=d;a.addEventListener?a.removeEventListener("error",b,!1):a.attachEvent&&a.detachEvent("onerror",b)};e(a,"load",d);b&&e(a,"error",d)};google.afte=!0;google.aft=function(a){google.c.c.a&&google.afte&&(google.timers.aft||google.startTick("aft"),google.timers.aft.t[a.id||a.src||a.name]=google.time())};google.c.b("pr");google.c.b("xe");}).call(this);})();(function(){var b={gen204:"dcl",clearcut:4};var c=[function(){google.c&&google.tick("load",b)}];google.dclc=function(a){c.length?c.push(a):a()};function d(){for(var a;a=c.shift();)a()}window.addEventListener?(document.addEventListener("DOMContentLoaded",d,!1),window.addEventListener("load",d,!1)):window.attachEvent&&window.attachEvent("onload",d);}).call(this);(function(){var b=[];google.jsc={xx:b,x:function(a){b.push(a)},mm:[],m:function(a){google.jsc.mm=a},aa:[],a:function(a){google.jsc.aa.push(a)},dd:[],d:function(a){google.jsc.dd.push(a)}};}).call(this);(function(){var g=this,h=Date.now||function(){return+new Date};var y={};var A=function(a,d){return function(b){b||(b=window.event);return d.call(a,b)}},B="undefined"!=typeof navigator&&/Macintosh/.test(navigator.userAgent),C=function(){this._mouseEventsPrevented=!0};var E=function(){this.v=[];this.g=[];this.h=[];this.s={};this.i=null;this.l=[];D(this,"_custom")},G="undefined"!=typeof navigator&&/iPhone|iPad|iPod/.test(navigator.userAgent),H=String.prototype.trim?function(a){return a.trim()}:function(a){return a.replace(/^\s+/,"").replace(/\s+$/,"")},I=/\s*;\s*/,M=function(a,d){return function(b){var c=d;if("_custom"==c){c=b.detail;if(!c||!c._type)return;c=c._type}var e;var f;"click"==c&&(B&&b.metaKey||!B&&b.ctrlKey||2==b.which||null==b.which&&4==b.button||b.shiftKey)&&
(c="clickmod");var x=b.srcElement||b.target,q=J(c,b,x,"",null);for(f=x;f&&f!=this;f=f.__owner||f.parentNode){var k=e=f;var F=c,l=k.__jsaction;if(!l){var r=K(k,"jsaction");if(r){l=y[r];if(!l){l={};for(var v=r.split(I),w=0,u=v?v.len
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
D/: HostConnection::get() New Host Connection established 0xa963f180, tid 13336
D/android.widget.GridLayout: vertical constraints: y5-y0>=1944, y5-y4<=168, y4-y3<=168, y3-y2<=168, y2-y1<=238, y1-y0<=1008 are inconsistent; permanently removing: y5-y4<=168.
D/: HostConnection::get() New Host Connection established 0xa963f480, tid 13427
I/OpenGLRenderer: Initialized EGL, version 1.4
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/EGL_emulation: eglCreateContext: 0xadd15080: maj 3 min 1 rcv 4
D/EGL_emulation: eglMakeCurrent: 0xadd15080: ver 3 1 (tinfo 0xaddbf730)
E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
glUtilsParamSize: unknow param 0x00008cdf
E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
D/EGL_emulation: eglMakeCurrent: 0xadd15080: ver 3 1 (tinfo 0xaddbf730)
W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
I/Choreographer: Skipped 112 frames! The application may be doing too much work on its main thread.
答案 0 :(得分:0)
您无法在UI线程上调用方法get()
。用您的doInBackground
方法而不是返回null
来返回结果。还应在onPostExecute
中覆盖AsyncTask
方法,在该方法中应处理结果。
答案 1 :(得分:0)
那是工作!只需查看您的日志即可:
<div class="col-md-3">
<label asp-for="Expression">@Html.DisplayFor(x => x.Expression)</label>
<input asp-for="Expression" type="hidden" />
</div>
这是google.com页面的内容。