首页 \ 问答 \ 具有多个标记解析错误的AsyncTask(AsyncTask with multiple tag parsing error)

具有多个标记解析错误的AsyncTask(AsyncTask with multiple tag parsing error)

 protected Void doInBackground(Void... params) {
        try {
            // Connect to the web site
            Document document = Jsoup.connect(url).get();
            // Using Elements to get the Meta data
            // Locate the content attribute
            Elements h3Tag = document.select("h3");

            desc1 = Integer.toString(h3Tag.size());
            if(Integer.parseInt(desc1)==1)
            {                
                Element description = document.getElementsByTag("table").get(3);
            }

在上面的代码中,每当我添加该行

document.getElementByTag("table").get(3));

该程序崩溃..但是,如果我删除h3tag选择它将工作正常..只有其中一个将工作,而不是两个..帮助?

日志

 01-12 16:33:26.314: E/AndroidRuntime(966):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.concurrent.FutureTask.run(FutureTask.java:239)
01-12 16:33:26.314: E/AndroidRuntime(966):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.lang.Thread.run(Thread.java:856)
01-12 16:33:26.314: E/AndroidRuntime(966): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 3, size is 3
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.ArrayList.get(ArrayList.java:304)
01-12 16:33:26.314: E/AndroidRuntime(966):  at org.jsoup.select.Elements.get(Elements.java:501)
01-12 16:33:26.314: E/AndroidRuntime(966):  at com.example.scrapping.MainActivity$Description.doInBackground(MainActivity.java:132)
01-12 16:33:26.314: E/AndroidRuntime(966):  at com.example.scrapping.MainActivity$Description.doInBackground(MainActivity.java:1)
01-12 16:33:26.314: E/AndroidRuntime(966):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
01-12 16:33:26.314: E/AndroidRuntime(966):  ... 4 more
01-12 16:33:29.355: E/WindowManager(966): Activity com.example.scrapping.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d42af0 V.E..... R......D 0,0-772,216} that was originally added here
01-12 16:33:29.355: E/WindowManager(966): android.view.WindowLeaked: Activity com.example.scrapping.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d42af0 V.E..... R......D 0,0-772,216} that was originally added here
01-12 16:33:29.355: E/WindowManager(966):   at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
01-12 16:33:29.355: E/WindowManager(966):   at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
01-12 16:33:29.355: E/WindowManager(966):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
01-12 16:33:29.355: E/WindowManager(966):   at android.app.Dialog.show(Dialog.java:281)
01-12 16:33:29.355: E/WindowManager(966):   at com.example.scrapping.MainActivity$Description.onPreExecute(MainActivity.java:116)
01-12 16:33:29.355: E/WindowManager(966):   at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
01-12 16:33:29.355: E/WindowManager(966):   at android.os.AsyncTask.execute(AsyncTask.java:534)
01-12 16:33:29.355: E/WindowManager(966):   at com.example.scrapping.MainActivity$2.onClick(MainActivity.java:55)
01-12 16:33:29.355: E/WindowManager(966):   at android.view.View.performClick(View.java:4204)
01-12 16:33:29.355: E/WindowManager(966):   at android.view.View$PerformClick.run(View.java:17355)
01-12 16:33:29.355: E/WindowManager(966):   at android.os.Handler.handleCallback(Handler.java:725)
01-12 16:33:29.355: E/WindowManager(966):   at android.os.Handler.dispatchMessage(Handler.java:92)
01-12 16:33:29.355: E/WindowManager(966):   at android.os.Looper.loop(Looper.java:137)
01-12 16:33:29.355: E/WindowManager(966):   at android.app.ActivityThread.main(ActivityThread.java:5041)
01-12 16:33:29.355: E/WindowManager(966):   at java.lang.reflect.Method.invokeNative(Native Method)
01-12 16:33:29.355: E/WindowManager(966):   at java.lang.reflect.Method.invoke(Method.java:511)
01-12 16:33:29.355: E/WindowManager(966):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-12 16:33:29.355: E/WindowManager(966):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-12 16:33:29.355: E/WindowManager(966):   at dalvik.system.NativeStart.main(Native Method)
01-12 16:33:31.285: I/Process(966): Sending signal. PID: 966 SIG: 9

 protected Void doInBackground(Void... params) {
        try {
            // Connect to the web site
            Document document = Jsoup.connect(url).get();
            // Using Elements to get the Meta data
            // Locate the content attribute
            Elements h3Tag = document.select("h3");

            desc1 = Integer.toString(h3Tag.size());
            if(Integer.parseInt(desc1)==1)
            {                
                Element description = document.getElementsByTag("table").get(3);
            }

In the above code, whenever i add the line

document.getElementByTag("table").get(3));

The program crashes.. however if i remove the h3tag select it will work fine.. only one of them will work at a time not both..help?

log

 01-12 16:33:26.314: E/AndroidRuntime(966):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.concurrent.FutureTask.run(FutureTask.java:239)
01-12 16:33:26.314: E/AndroidRuntime(966):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.lang.Thread.run(Thread.java:856)
01-12 16:33:26.314: E/AndroidRuntime(966): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 3, size is 3
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.ArrayList.get(ArrayList.java:304)
01-12 16:33:26.314: E/AndroidRuntime(966):  at org.jsoup.select.Elements.get(Elements.java:501)
01-12 16:33:26.314: E/AndroidRuntime(966):  at com.example.scrapping.MainActivity$Description.doInBackground(MainActivity.java:132)
01-12 16:33:26.314: E/AndroidRuntime(966):  at com.example.scrapping.MainActivity$Description.doInBackground(MainActivity.java:1)
01-12 16:33:26.314: E/AndroidRuntime(966):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-12 16:33:26.314: E/AndroidRuntime(966):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
01-12 16:33:26.314: E/AndroidRuntime(966):  ... 4 more
01-12 16:33:29.355: E/WindowManager(966): Activity com.example.scrapping.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d42af0 V.E..... R......D 0,0-772,216} that was originally added here
01-12 16:33:29.355: E/WindowManager(966): android.view.WindowLeaked: Activity com.example.scrapping.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d42af0 V.E..... R......D 0,0-772,216} that was originally added here
01-12 16:33:29.355: E/WindowManager(966):   at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
01-12 16:33:29.355: E/WindowManager(966):   at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
01-12 16:33:29.355: E/WindowManager(966):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
01-12 16:33:29.355: E/WindowManager(966):   at android.app.Dialog.show(Dialog.java:281)
01-12 16:33:29.355: E/WindowManager(966):   at com.example.scrapping.MainActivity$Description.onPreExecute(MainActivity.java:116)
01-12 16:33:29.355: E/WindowManager(966):   at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
01-12 16:33:29.355: E/WindowManager(966):   at android.os.AsyncTask.execute(AsyncTask.java:534)
01-12 16:33:29.355: E/WindowManager(966):   at com.example.scrapping.MainActivity$2.onClick(MainActivity.java:55)
01-12 16:33:29.355: E/WindowManager(966):   at android.view.View.performClick(View.java:4204)
01-12 16:33:29.355: E/WindowManager(966):   at android.view.View$PerformClick.run(View.java:17355)
01-12 16:33:29.355: E/WindowManager(966):   at android.os.Handler.handleCallback(Handler.java:725)
01-12 16:33:29.355: E/WindowManager(966):   at android.os.Handler.dispatchMessage(Handler.java:92)
01-12 16:33:29.355: E/WindowManager(966):   at android.os.Looper.loop(Looper.java:137)
01-12 16:33:29.355: E/WindowManager(966):   at android.app.ActivityThread.main(ActivityThread.java:5041)
01-12 16:33:29.355: E/WindowManager(966):   at java.lang.reflect.Method.invokeNative(Native Method)
01-12 16:33:29.355: E/WindowManager(966):   at java.lang.reflect.Method.invoke(Method.java:511)
01-12 16:33:29.355: E/WindowManager(966):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-12 16:33:29.355: E/WindowManager(966):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-12 16:33:29.355: E/WindowManager(966):   at dalvik.system.NativeStart.main(Native Method)
01-12 16:33:31.285: I/Process(966): Sending signal. PID: 966 SIG: 9

原文:
更新时间:2021-06-16 07:06

最满意答案

我想你需要

df <- within(df, V1 <- relevel(V1, ref="Yes"))

因为relevel返回因子的相关值,但不会将其赋值给变量。 您正在评估 df的表达式,但不会将其分配给任何内容。 我可能会用

df <- transform(df, V1 = relevel(V1, ref="Yes"))

相反,但这是一种风格偏好(另见plyr / dplyr函数mutatedplyr ......)

如果(在评论中提到)你有一个名字向量(即一个字符向量),那么你就不能真正使用由transform共享的非标准评估范式, within subsetdplyr ...)但是或多或少必须以老式的方式做事,例如

df[vars.to.relevel] <- lapply(df[vars.to.relevel],relevel,ref="Yes")   

I think you need

df <- within(df, V1 <- relevel(V1, ref="Yes"))

because relevel returns the relevelled value of the factor but doesn't assign it to a variable. You're evaluating the expression within df, but not assigning it to anything. I would probably use

df <- transform(df, V1 = relevel(V1, ref="Yes"))

instead, but that's a stylistic preference (see also the plyr/dplyr functions mutate, transmute ...)

If (as asked in the comments) you have a vector of names (i.e. a character vector), then you can't really use the non-standard evaluation paradigm shared by transform, with, within, subset (dplyr ...) but more or less have to do things the old-fashioned way, e.g.

df[vars.to.relevel] <- lapply(df[vars.to.relevel],relevel,ref="Yes")   

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)