document = Jsoup.connect(url).get();不断崩溃我的应用程序

时间:2014-12-25 02:54:13

标签: android

public class MainActivity extends Activity {

static String question;
static Document document = null;
static String url = "https://www.cryptsy.com/markets/view/CLAM_BTC";
TextView price;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    price = (TextView) findViewById(R.id.textView1);
    new Read().execute();

}

 private class Read extends AsyncTask<Void, Void, Void> {

    @Override
    protected Void doInBackground(Void... params) {
         try {
                document = Jsoup.connect(url).get();
            } catch (IOException e1) {
                e1.printStackTrace();
         }
                question = document.select("#market_price_462").text();
                System.out.println("Question: " + question); 
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        price.setText(question);
    }
 }


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

当我运行应用程序时,它会立即崩溃,我知道document = Jsoup.connect(url).get();导致它,因为当我编辑尝试catch语句时,应用程序运行。 我允许在清单中进行互联网访问,所以我不确定是什么造成这种情况。

0 个答案:

没有答案