0

I have created an Android app that I would like to supply with some info scraped from a page. I used JSoup, and was succesfully able to scrape all of the HTML, and place them into the proper data structures in a console project, with a single class name Scraper.java.

My next step was to port this Scraper.java into my Android app. To do this I simply wanted to make a Scraper object in my activity that I need the html info for. This didn't seem to work, and I was getting an error that seems as if it was trying to tell me that Android didn't like this external class trying to connect to the internet.

Giving up I very dirtily dumped all of the code from Scraper.java into my Activity class and got it to scrape the data fine, and it connected without any issue.

The problem now is that I realize I want to access that complex data in other Activities, and it really would be much simpler for me to just go back to trying to have an external Scraper.java file so I can share an object of it rather than all of the data types inside of it.

So my question is, what do I need to do to let Android know that it doesn't need to freak out, and can let my external Scraper.java file connect.

I have allowed the permission for internet in the manifest so I am lost as for what to do from here.

4

1 に答える 1

0

非常にばかげたエラーが発生したことがわかり、コードが機能するようになりました。返信が遅れてすみません、昨夜はとても忙しかったです。

私が抱えていた問題は、コンソールバージョンを移植したときに、Androidアプリと衝突していたScraper.javaファイルのmainメソッドに残っていたということでした。コードをさらにクリーンアップし、Scraper.javaオブジェクトを非常に簡単に参照できるようになりました。

作成したオブジェクトのインスタンスの共有を改善するには、Scraper.javaファイルを使用してParcelableを実装し、複数のアクティビティ間でインスタンスを簡単に共有できるようにするつもりです。興味のある方はhttp://prasanta-paul.blogspot.com/2010/06/android-parcelable-example.htmlを参照してください。

于 2012-11-08T18:00:47.987 に答える