protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.test);
super.onCreate(savedInstanceState);
Log.d("ERR", "entered into oncreate");
Thread t=new Thread(
new Runnable() {
public void run(){
String url="https://www.google.co.in/gfe_rd=cr&ei=ySm0U9fCNY7V8gec7oGwAw&gws_rd=ssl";
try {
Document doc = Jsoup.connect(url).get();
Log.d("ERR", "connected jsoup");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}});
t.start();
try {
t.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
应用程序意外关闭。我一直在尝试在互联网上找到的所有方法,包括异步任务,它最终会在"应用程序意外关闭"
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testing"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.testing.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.testing.DetailedActivity"></activity>
</application>
</manifest>
在其他方法中,我使用了AsyncTask方法,代码如下所示。
public class Jsync extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
Log.d("ERR", "entered into pre-execute");
// TODO Auto-generated method stub
super.onPreExecute();
ProgressDialog progress;
}
@Override
protected Void doInBackground(Void... params) {
Log.d("ERR", "entered into do-in-background");
String url="https://drive.google.com/folderview?id=0BwjWHVIIojsMWHRlYXpza3FFYm8&usp=sharing";
try {
org.jsoup.nodes.Document doc = Jsoup.connect(url).get();
Log.d("ERR", "connected by jsoup");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
}
顺便说一句,我是android的新手。谢谢你