force close when assign onclick to button

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

force close when assign onclick to button

Postby lynnooi » Mon Dec 21, 2009 9:57 am

hi,

i am very new in android development as well as in java. i had developed an application that gets an image url from a site and wanted to download it into the device and later on i would like to enable users to set it as wallpapers. however, i am met a problem when assigning onclick event to a button. Once i uncomment the line in red, it will pop up a box stating that the application was stopped unexpectedly. Can someone help me with this?
[syntax="java"][code]private ImageView imView = null;

public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);

try {
/* Create a URL we want to load some xml-data from. */
URL url = new URL(xmlURL);
/* Get a SAXParser from the SAXPArserFactory. */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();

/* Get the XMLReader of the SAXParser we created. */
XMLReader xr = sp.getXMLReader();
/* Create a new ContentHandler and apply it to the XML-Reader */
ExampleHandler myExampleHandler = new ExampleHandler();
xr.setContentHandler(myExampleHandler);

/* Parse the xml-data from our URL. */
xr.parse(new InputSource(url.openStream()));
/* Parsing has finished. */

/* Our ExampleHandler now provides the parsed data to us. */
ParsedExampleDataSet parsedExampleDataSet = myExampleHandler
.getParsedData();

/* Set the result to be displayed in our GUI. */
if (myExampleHandler.filenames != null) {
a = a + "\n" + myExampleHandler.filenames + ", by "
+ myExampleHandler.authors + "\nhits: "
+ myExampleHandler.hits + " downloads";
this.ed = myExampleHandler.thumbs;
this.imageURL = myExampleHandler.mediafiles;
}
} catch (Exception e) {
a = e.getMessage();
}

// get thumbnail
Context context = this.getBaseContext();
if (ed.length() != 0) {
Drawable image = ImageOperations(context, this.ed, "image.jpg");
ImageView imgView = new ImageView(context);
imgView = (ImageView) findViewById(R.id.image1);
imgView.setImageDrawable(image);
}

TextView tv = (TextView) findViewById(R.id.txt_name);
tv.setText(a);

Button bt3 = (Button) findViewById(R.id.get_imagebt);
//bt3.setOnClickListener(getImageBtnOnClick);
}

OnClickListener getImageBtnOnClick = new OnClickListener() {
public void onClick(View view) {
downloadFile(imageURL);
}
};
lynnooi
Freshman
Freshman
 
Posts: 2
Joined: Mon Dec 21, 2009 9:32 am

Top

Postby qlimax » Mon Dec 21, 2009 11:23 am

http://www.anddev.org/the_application_- ... t3452.html

eclipse->window->showview->other->android->logcat


bye :roll:
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 8 guests