• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Android app keeps crashing...

ikiwi

Lurker
Dec 23, 2014
1
0
This is the code:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.Timer;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class MainActivity extends Activity {

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

class fetcher extends AsyncTask<Void,Void, Void>{
//HERE DECLARE THE VARIABLES YOU USE FOR PARSING
Element overview=null;
private Element featureList=null;
private Elements features=null;
private Element paragraph =null;
@override
protected Void doInBackground(Void... arg0) {
Document doc = null;
try {
doc = Jsoup.connect(url).get();
overview = doc.select("#market_price_462").last();
// featureList = doc.select("div.callout-box").last();

//features = featureList.select("li");
paragraph = overview.select("p").last();
System.out.println(paragraph.text());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

// Get the paragraph element
article.setText(paragraph.text()); //I comment this out because you cannot update ui from non-ui thread, since doInBackground is running on background thread.


return null;
}
@override
protected void onPostExecute(Void result)
{

article = (TextView)findViewById(R.id.price);
// final TextView featuresText = (TextView)findViewById(R.id.features);
// for(Element e: features)
article.setText(overview.text());
// article.setText("246");


}

}



@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MainActivity main = new MainActivity();
article.setText(overview.text());

}



@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);
}
}


I know when i set the text for article in the onCreate method it causes the app to crash, but i dont know why and how to fix it.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones