What's the problem?

Put your problem here if it does not fit any of the other categories.

What's the problem?

Postby songotho » Wed Mar 11, 2009 6:55 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

Postby mortefer » Wed Mar 11, 2009 1:03 pm

put your sample.xml file to "raw" folder, not "xml". SAXParser doesnt parse xmls from "xml" folder - seems there is some symbol being added to the beginning of the file.
mortefer
Experienced Developer
Experienced Developer
 
Posts: 54
Joined: Sat Dec 20, 2008 11:24 am

Postby songotho » Wed Mar 11, 2009 4:47 pm

I have put the sample.xml to raw folder so it's error.
I dont know the error:( :(
songotho
Experienced Developer
Experienced Developer
 
Posts: 55
Joined: Tue Mar 03, 2009 1:59 am

Postby songotho » Fri Mar 13, 2009 6:51 am

I have tried to modify it so it's error, would anyone help me about this?
I created the other file.java so I don't know why it's error
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class Test1 extends Activity{
  3.  
  4.         /** Called when the activity is first created. */
  5.  
  6.        
  7.  
  8.        
  9.  
  10.     @Override
  11.  
  12.     public void onCreate(Bundle savedInstanceState) {
  13.  
  14.         super.onCreate(savedInstanceState);
  15.  
  16.         //setContentView(R.layout.main);  
  17.  
  18.         readfilefromlocal(this);
  19.  
  20.     }  
  21.  
  22.    
  23.  
  24.         protected void readfilefromlocal(Context ctx) {
  25.  
  26.        
  27.  
  28.         FileInputStream istream = null;
  29.  
  30.         TextView tv = new TextView (this);
  31.  
  32.         try {
  33.  
  34.                 istream = (FileInputStream)ctx.getResources().openRawResource(R.raw.sample);
  35.  
  36.  
  37.  
  38.                 /* Get a SAXParser from the SAXPArserFactory. */
  39.  
  40.                 SAXParserFactory spf = SAXParserFactory.newInstance();
  41.  
  42.                 SAXParser sp = spf.newSAXParser();
  43.  
  44.                 /* Get the XMLReader of the SAXParser we created. */
  45.  
  46.                 XMLReader xr = sp.getXMLReader();
  47.  
  48.                 /* Create a new ContentHandler and apply it to the XML-Reader*/
  49.  
  50.                 ExampleHandler myExampleHandler = new ExampleHandler();
  51.  
  52.                 xr.setContentHandler(myExampleHandler);
  53.  
  54.                 /* Parse the xml-data from our URL. */
  55.  
  56.                 xr.parse(new InputSource(istream));
  57.  
  58.                 /* Parsing has finished. */
  59.  
  60.        
  61.  
  62.                 /* Our ExampleHandler now provides the parsed data to us. */
  63.  
  64.                 ParsedExampleDataSet parsedExampleDataSet = myExampleHandler.getParsedData();
  65.  
  66.                 /* Set the result to be displayed in our GUI. */
  67.  
  68.                 tv.setText(parsedExampleDataSet.toString1());
  69.  
  70.                
  71.  
  72.         }
  73.  
  74.         catch (Exception e){
  75.  
  76.                 tv.setText("Error: " + e.getMessage());
  77.  
  78.         }
  79.  
  80.         this.setContentView(tv);    
  81.  
  82.     }
  83.  
  84.  
  85.  
  86. }
  87.  
  88.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


And there's the error: "android.content.res.AssetManager$AssetInputStream"
Anyone help me?
Thanks.
--Alex
songotho
Experienced Developer
Experienced Developer
 
Posts: 55
Joined: Tue Mar 03, 2009 1:59 am

Postby songotho » Mon Mar 16, 2009 6:27 am

I need read file in sdcard, anyone help me, please?
songotho
Experienced Developer
Experienced Developer
 
Posts: 55
Joined: Tue Mar 03, 2009 1:59 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 10 guests