<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Mo Jebus &#187; Java</title>
	<link>http://moronicbajebus.com</link>
	<description>Banana Ice Cream!</description>
	<pubDate>Wed, 06 Aug 2008 14:30:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>
	<language>en</language>
			<item>
		<title>Package Troubleshooting</title>
		<link>http://moronicbajebus.com/2006/02/13/package-troubleshooting/</link>
		<comments>http://moronicbajebus.com/2006/02/13/package-troubleshooting/#comments</comments>
		<pubDate>Tue, 14 Feb 2006 02:59:48 +0000</pubDate>
		<dc:creator>Seamus</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[Frontpage]]></category>

		<guid isPermaLink="false">http://moronicbajebus.com/?p=65</guid>
		<description><![CDATA[A simply learned lesson in using Java packages causing the errors out the wa-zoo when trying to run the program.]]></description>
			<content:encoded><![CDATA[<p>I had trouble with my early Java programs when I would use <a href="http://www.yoda.arachsys.com/java/packages.html">packages</a>.  If I left my files in the default package, it worked fine. But when I added them to a package, I could build them finejust not run them.  I found it to be a common problem among other students and I spent far too much time trying to search for an answer.</p>
<p>ExampleWithPackage.java source:<code>
<pre>package com.moronicbajebus; 

public class ExampleWithPackage {
	public static void main(String[] args) {
		//&#8230;
	}
}</pre>
<p></code></p>
<p>The error output from running it in the command line from the directory <code>working-directory</code>:<br />
<code>
<pre>.../working-directory&gt;java ExampleWithPackage
Exception in thread "main" java.lang.NoClassDefFoundError: ExampleWithPackage (wrong name: com/moronicbajebus/ExampleWithPackage)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)</pre>
<p></code></p>
<p><strong>The java files must be in directory tree that matches the package name</strong> from the working directory (the one you are in if you are using a command line).  I need to create a directory named <code>com</code> in <code>working-directory</code>; and then, I need to create a directory named <code>moronicbajebus</code> in the newly created <code>com</code> directory. Then I place <code>ExampleWithPackage.java</code> in the  <code>moronicbajebus</code> directory. </p>
<p>Now the program will run with one more minor change, Now the program will run with one more minor change, I have to also give the package with the class:<br />
<code>.../working-directory&gt;java <strong>com.moronicbajebus.</strong>ExampleWithPackage</code></p>
<p>Remember dont choke your computer, <a href="http://gallery.actsofvolition.com/photos/signs/photo25270">choke your dog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://moronicbajebus.com/2006/02/13/package-troubleshooting/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
