tags:

views:

70

answers:

1

Hello. I am new with Scala and I am writing a simple rss reader. I have class Manager for managing feeds and content.

package lib
import scala.xml._
import java.net.URL
import net.liftweb.couchdb.{CouchDB, Database}
import dispatch.{Http, StatusCode}

/**
 * @author smix
 * 
 * Feeds manager
 */
object Manager {
 var db = List[Database]()
 /*
  * Initialize CouchDb databases
  */
 def init = {
  this.appendDb(new Database("myserver.com", 5984, "content"))
 }

 /*
  * Append a new database to the databases list
  */
 private def appendDb(database: Database) : Unit = {
  database :: db 
  // Strange exception if database has been already created
  /* try {
   this.db.head.createIfNotCreated(new Http())
  } catch {
   case e:java.lang.NoClassDefFoundError => {}
  } */
 }

 /*
  * Fetch articles from feed by url
  */
    def fetchItems(feedUrl: String): List[scala.xml.Elem] = { 
   val rssFeed = XML.load( (new URL(feedUrl)).openConnection.getInputStream )
   val items = rssFeed \ "channel" \ "item"

   val articles: List[scala.xml.Elem] = List()
   for(item <- items) {
      item :: articles
   }

   articles
    }

}

I want to store content in CouchDb. I need to have list of couch databases(feeds, articles, etc...). I wrote class but when I call appendDb i get an error:

Exception in thread "main" java.lang.NoClassDefFoundError: lib/Manager$
 at collector$.main(collector.scala:5)
 at collector.main(collector.scala)
Caused by: java.lang.ClassNotFoundException: lib.Manager$
 at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
 ... 2 more

When I rewrited db definition: var db = List[Int]() and the first line of appendDb: 1 :: this.db project ran fine... Strange.

Also, it is interesting why am I getting exception when I call createIfNotCreated for existing database(commented try-catch block in appendDb).

+2  A: 

The exception indicates that you're missing some classes (one or more JAR files, presumably) when you run your program, though they're either irrelevant to compiling it or they are available then.

You should also note that the first line in appendDb accomplishes nothing. It builds a new List by consing database onto the front of the List referred to by db, but the resulting value is discarded. Perhaps you meant this:

  db = database :: db
Randall Schulz
Thanks. I will try to find missing jar...
SMiX