Java Question I don´t know what is happen

invaderwt

Member
Licensed User
Longtime User
works in the eclipse but when I try instance in b4a stop.
I think with some one can help me
If this class work I will probably finsh and try post this class to read of feedsburn.

I´ve tried a lot of thing but the error is the same whe I tried this ( " Dim gerador As XMLLeitorFeed ")
I don´t know how resolv or what I did wrong
I use java 1.6

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim ListView1 As ListView
   

End Sub

Sub Activity_Create(FirstTime As Boolean)

Activity.LoadLayout("3")

Dim gerador As XMLLeitorFeed
Dim teste As XMLPodCast
Dim canal As XMLCanal
ListView1.AddSingleLine("TEste")

'gerador.GeraRSSFeedParser("http://feeds.feedburner.com/AnimeFreakShowV40PodcastESpin-offs")
'canal = gerador.canal





End Sub
 

Attachments

  • XMLpodCast.zip
    15.4 KB · Views: 336
  • 3.bal
    1.4 KB · Views: 281
Last edited:

invaderwt

Member
Licensed User
Longtime User
the classe the b4a don´t load it´s that
B4X:
package xmlpodCast.castrohs.com;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;

import anywheresoftware.b4a.BA.ShortName;



@ShortName("XMLLeitorFeed")
public class XMLLeitorFeed {
   private String TITLE = "title";
   private String DESCRIPTION = "description";
//   private String CHANNEL = "channel";
   private String LANGUAGE = "language";
   private String COPYRIGHT = "copyright";
   private String LINK = "origLink";
   private String AUTHOR = "author";
   private String ITEM = "item";
   private String PUB_DATE = "pubDate";
   private String GUID = "guid";
   private String DURATION = "duration";
   private String ENCLOSURE = "origEnclosureLink";
   private URL url;
   private XMLCanal feed= null;
   
   public XMLLeitorFeed(){
   }
   
   

   /**
    * 
    * Create a feed from url
    * and run to canal
    *  
    */
   
   public void GeraRSSFeedParser(String feedUrl) {
      try {
         this.url = new URL(feedUrl);
         if (url!=null)
            readFeed();
         
      
      } catch (MalformedURLException e) {
         
      }
      
      
   }
   


   public URL getUrl() {
      return url;
   }


   public void setUrl(URL url) {
      this.url = url;
   }
/*
   private InputStream read() {
      try {
         return url.openStream();
      } catch (IOException e) {
         throw new RuntimeException(e);
      }
   }
   */

   public XMLCanal readFeed() {
      //XMLCanal feed = null;
      try {

         boolean isFeedHeader = true;
         // Set header values inicia to the empty string
         String description = "";
         String title = "";
         String link = "";
         String language = "";
         String copyright = "";
         String author = "";
         String pubdate = "";
         String guid = "";
         String duration = "0.0";
         String enclosure = "";

         // First create a new XMLInputFactory
         XMLInputFactory inputFactory = XMLInputFactory.newInstance();
         // Setup a new eventReader
         
         InputStream in = null;
         try {
            in = url.openStream();
         } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
         if (in!=null){
         XMLEventReader eventReader = inputFactory.createXMLEventReader(in);
         // Read the XML document
         while (eventReader.hasNext()) {

            XMLEvent event = eventReader.nextEvent();

            if (event.isStartElement()) {
               if (event.asStartElement().getName().getLocalPart() == (ITEM)) {
                  if (isFeedHeader) {
                     isFeedHeader = false;
                     feed = new XMLCanal(title, link, description, language,
                           copyright, pubdate);
                  }
                  event = eventReader.nextEvent();
                  continue;
               }

               if (event.asStartElement().getName().getLocalPart() == (TITLE)) {
                  event = eventReader.nextEvent();
                  title = event.asCharacters().getData();
                  continue;
               }
               if (event.asStartElement().getName().getLocalPart() == (DESCRIPTION)) {
                  event = eventReader.nextEvent();
                  description = event.asCharacters().getData();
                  continue;
               }
/*
               if (event.asStartElement().getName().getLocalPart() == (LINK)) {
                  event = eventReader.nextEvent();
                  link = event.asCharacters().getData();
                  continue;
               }*/

               if (event.asStartElement().getName().getLocalPart() == (GUID)) {
                  event = eventReader.nextEvent();
                  guid = event.asCharacters().getData();
                  continue;
               }
               if (event.asStartElement().getName().getLocalPart() == (LANGUAGE)) {
                  event = eventReader.nextEvent();
                  language = event.asCharacters().getData();
                  continue;
               }
               if (event.asStartElement().getName().getLocalPart() == (AUTHOR)) {
                  event = eventReader.nextEvent();
                  author = event.asCharacters().getData();
                  continue;
               }
               if (event.asStartElement().getName().getLocalPart() == (PUB_DATE)) {
                  event = eventReader.nextEvent();
                  pubdate = event.asCharacters().getData();
                  continue;
               }
               if (event.asStartElement().getName().getLocalPart() == (COPYRIGHT)) {
                  event = eventReader.nextEvent();
                  copyright = event.asCharacters().getData();
                  continue;
               }
               if (event.asStartElement().getName().getLocalPart() == (ENCLOSURE)) {
                  event = eventReader.nextEvent();
                  enclosure = event.asCharacters().getData();
                  continue;
               } 
               if (event.asStartElement().getName().getLocalPart() == (DURATION)) {
                  event = eventReader.nextEvent();
                  duration = event.asCharacters().getData();
                  continue;
               } 
               if (event.asStartElement().getName().getLocalPart() == (LINK)) {
                  event = eventReader.nextEvent();
                  link = event.asCharacters().getData();
                  continue;
               } 

            } else if (event.isEndElement()) {
               if (event.asEndElement().getName().getLocalPart() == (ITEM)) {
                  XMLPodCast message = new XMLPodCast();
                  message.setAuthor(author);
                  message.setDescription(description);
                  message.setGuid(guid);
                  message.setLink(link);
                  message.setTitle(title);
                  message.setDuracao(duration);
                  message.setEnclosure(enclosure);
                  feed.addMessages(message);
                  event = eventReader.nextEvent();
                  continue;
               }
            }
         }
         }
      } catch (XMLStreamException e) {
         throw new RuntimeException(e);
      }
      
      return feed;

   }



   public XMLCanal getCanal() {
      return feed;
   }


   public void setCanal(XMLCanal feed) {
      this.feed = feed;
   }



   public String getTITLE() {
      return TITLE;
   }



   public void setTITLE(String tITLE) {
      TITLE = tITLE;
   }



   public String getDESCRIPTION() {
      return DESCRIPTION;
   }



   public void setDESCRIPTION(String dESCRIPTION) {
      DESCRIPTION = dESCRIPTION;
   }



   public String getLANGUAGE() {
      return LANGUAGE;
   }



   public void setLANGUAGE(String lANGUAGE) {
      LANGUAGE = lANGUAGE;
   }



   public String getCOPYRIGHT() {
      return COPYRIGHT;
   }



   public void setCOPYRIGHT(String cOPYRIGHT) {
      COPYRIGHT = cOPYRIGHT;
   }



   public String getLINK() {
      return LINK;
   }



   public void setLINK(String lINK) {
      LINK = lINK;
   }



   public String getAUTHOR() {
      return AUTHOR;
   }



   public void setAUTHOR(String aUTHOR) {
      AUTHOR = aUTHOR;
   }



   public String getITEM() {
      return ITEM;
   }



   public void setITEM(String iTEM) {
      ITEM = iTEM;
   }



   public String getPUB_DATE() {
      return PUB_DATE;
   }



   public void setPUB_DATE(String pUB_DATE) {
      PUB_DATE = pUB_DATE;
   }



   public String getGUID() {
      return GUID;
   }



   public void setGUID(String gUID) {
      GUID = gUID;
   }



   public String getDURATION() {
      return DURATION;
   }



   public void setDURATION(String dURATION) {
      DURATION = dURATION;
   }



   public String getENCLOSURE() {
      return ENCLOSURE;
   }



   public void setENCLOSURE(String eNCLOSURE) {
      ENCLOSURE = eNCLOSURE;
   }
   
   
}
 

invaderwt

Member
Licensed User
Longtime User
ok only the error it´s show up it´s in the image.


I tried debbug but nothing happen.

I used this.:
@Permissions(values = {"android.permission.INTERNET"})

I know the error it´s caused by this method
B4X:
public void readFeed() {
           //XMLCanal feed = null;
           try {

               boolean isFeedHeader = true;
               // Set header values inicia to the empty string
               String description = "";
               String title = "";
               String link = "";
               String language = "";
               String copyright = "";
               String author = "";
               String pubdate = "";
               String guid = "";
               String duration = "0.0";
               String enclosure = "";

               // First create a new XMLInputFactory
               XMLInputFactory inputFactory = XMLInputFactory.newInstance();
               // Setup a new eventReader
               
               InputStream in = null;
               try {
                   in = url.openStream();
               } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
               }
               if (in!=null){
               XMLEventReader eventReader = inputFactory.createXMLEventReader(in);
               // Read the XML document
               while (eventReader.hasNext()) {

                   XMLEvent event = eventReader.nextEvent();

                   if (event.isStartElement()) {
                       if (event.asStartElement().getName().getLocalPart() == (ITEM)) {
                           if (isFeedHeader) {
                               isFeedHeader = false;
                               feed = new XMLCanal(title, link, description, language,
                                       copyright, pubdate);
                           }
                           event = eventReader.nextEvent();
                           continue;
                       }

                       if (event.asStartElement().getName().getLocalPart() == (TITLE)) {
                           event = eventReader.nextEvent();
                           title = event.asCharacters().getData();
                           continue;
                       }
                       if (event.asStartElement().getName().getLocalPart() == (DESCRIPTION)) {
                           event = eventReader.nextEvent();
                           description = event.asCharacters().getData();
                           continue;
                       }
   /*
                       if (event.asStartElement().getName().getLocalPart() == (LINK)) {
                           event = eventReader.nextEvent();
                           link = event.asCharacters().getData();
                           continue;
                       }*/

                       if (event.asStartElement().getName().getLocalPart() == (GUID)) {
                           event = eventReader.nextEvent();
                           guid = event.asCharacters().getData();
                           continue;
                       }
                       if (event.asStartElement().getName().getLocalPart() == (LANGUAGE)) {
                           event = eventReader.nextEvent();
                           language = event.asCharacters().getData();
                           continue;
                       }
                       if (event.asStartElement().getName().getLocalPart() == (AUTHOR)) {
                           event = eventReader.nextEvent();
                           author = event.asCharacters().getData();
                           continue;
                       }
                       if (event.asStartElement().getName().getLocalPart() == (PUB_DATE)) {
                           event = eventReader.nextEvent();
                           pubdate = event.asCharacters().getData();
                           continue;
                       }
                       if (event.asStartElement().getName().getLocalPart() == (COPYRIGHT)) {
                           event = eventReader.nextEvent();
                           copyright = event.asCharacters().getData();
                           continue;
                       }
                       if (event.asStartElement().getName().getLocalPart() == (ENCLOSURE)) {
                           event = eventReader.nextEvent();
                           enclosure = event.asCharacters().getData();
                           continue;
                       } 
                       if (event.asStartElement().getName().getLocalPart() == (DURATION)) {
                           event = eventReader.nextEvent();
                           duration = event.asCharacters().getData();
                           continue;
                       } 
                       if (event.asStartElement().getName().getLocalPart() == (LINK)) {
                           event = eventReader.nextEvent();
                           link = event.asCharacters().getData();
                           continue;
                       } 

                   } else if (event.isEndElement()) {
                       if (event.asEndElement().getName().getLocalPart() == (ITEM)) {
                           XMLPodCast message = new XMLPodCast();
                           message.setAuthor(author);
                           message.setDescription(description);
                           message.setGuid(guid);
                           message.setLink(link);
                           message.setTitle(title);
                           message.setDuracao(duration);
                           message.setEnclosure(enclosure);
                           feed.addMessages(message);
                           event = eventReader.nextEvent();
                           continue;
                       }
                   }
               }
               }
           } catch (XMLStreamException e) {
               throw new RuntimeException(e);
           }
           
     //      return feed;

       }

and I try analysing why this error it´s happen I don´t know why.
 
Last edited:
Top