What's the problem?

Tutorials with advanced 'difficulty' and more Lines of Code.

What's the problem?

Postby songotho » Wed Mar 11, 2009 6:07 am

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. protected Dialog onCreateDialog(int id, Context ctx) {
  3.  
  4.        
  5.  
  6.         FileInputStream istream = null;
  7.  
  8.         try {
  9.  
  10.                 istream = (FileInputStream) ctx.getResources().openRawResource(R.xml.sample);
  11.  
  12.  
  13.  
  14.                 /* Get a SAXParser from the SAXPArserFactory. */
  15.  
  16.                 SAXParserFactory spf = SAXParserFactory.newInstance();
  17.  
  18.                 SAXParser sp = spf.newSAXParser();
  19.  
  20.                 /* Get the XMLReader of the SAXParser we created. */
  21.  
  22.                 XMLReader xr = sp.getXMLReader();
  23.  
  24.                 /* Create a new ContentHandler and apply it to the XML-Reader*/
  25.  
  26.                 ExampleHandler myExampleHandler = new ExampleHandler();
  27.  
  28.                 xr.setContentHandler(myExampleHandler);
  29.  
  30.                 /* Parse the xml-data from our URL. */
  31.  
  32.                 xr.parse(new InputSource(istream));
  33.  
  34.                 /* Parsing has finished. */
  35.  
  36.        
  37.  
  38.                 /* Our ExampleHandler now provides the parsed data to us. */
  39.  
  40.                 ParsedExampleDataSet parsedExampleDataSet = myExampleHandler.getParsedData();
  41.  
  42.                
  43.  
  44.                 switch (id) {
  45.  
  46.                 case DIALOG_MESSAGE:
  47.  
  48.                     return new AlertDialog.Builder(MainMenu.this)
  49.  
  50.                         //.setIcon(R.drawable.dialog_icon)
  51.  
  52.                         .setTitle("Test set text from local file")
  53.  
  54.                         .setMessage(parsedExampleDataSet.toString1())
  55.  
  56.                         .setPositiveButton("OK", new DialogInterface.OnClickListener() {
  57.  
  58.                             public void onClick(DialogInterface dialog, int whichButton) {
  59.  
  60.            
  61.  
  62.                                 /* User clicked OK so do some stuff */
  63.  
  64.                             }
  65.  
  66.                         })
  67.  
  68.                         .setNeutralButton("Something", new DialogInterface.OnClickListener() {
  69.  
  70.                             public void onClick(DialogInterface dialog, int whichButton) {
  71.  
  72.  
  73.  
  74.                                 /* User clicked Something so do some stuff */
  75.  
  76.                             }
  77.  
  78.                         })
  79.  
  80.                         .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  81.  
  82.                             public void onClick(DialogInterface dialog, int whichButton) {
  83.  
  84.  
  85.  
  86.                                 /* User clicked Cancel so do some stuff */
  87.  
  88.                             }
  89.  
  90.                         })
  91.  
  92.                         .create();
  93.  
  94.                 }
  95.  
  96.         }
  97.  
  98.         catch (Exception e){
  99.  
  100.                 e.getMessage();
  101.  
  102.         }
  103.  
  104.         return null;    
  105.  
  106.     }
  107.  
  108.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


I don't know that what is the problem in here? When I run the application which don't have error, so I click the button to call the function - it's error.
Thanks.
songotho
Experienced Developer
Experienced Developer
 
Posts: 55
Joined: Tue Mar 03, 2009 1:59 am

Top

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 8 guests