Results 1 to 5 of 5
- 01-31-2013, 09:22 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 30
- Rep Power
- 0
could not find or load main class com.javasrc.webphotogallery.LoadImage
Hello there!
I have a project in Enterprise Architecture called "Photo Gallery Management" .
I decided to create a web photo gallery.As I am "new" in Java i decided to follow a step by step tutorial which is : Java Reference Guide | Project: Building a Web Photo Gallery | InformIT
I installed Jboss,configured it on Eclipse.Then installed MySQL and MySQL Administrator becouse i have to build the database and so on.
I created the webphotogallery-ds.xml and stored it in the deploy folder of Jboss then I had to create a java code to put an image to the database table named ' images' .The code is:
To execute the LoadImage class, I need to include the MySQL JDBC JAR file in my CLASSPATH as follows:Java Code:package com.javasrc.webphotogallery; import java.io.*; import java.sql.*; public class LoadImage { public static void main( String[] args ) { if( args.length < 3 ) { System.out.println( "Usage: LoadImage <image-filename> <album-id> <desc>" ); System.exit( 0 ); } String filename = args[ 0 ]; int albumId = Integer.parseInt( args[ 1 ] ); String desc = args[ 2 ]; Connection conn = null; PreparedStatement ps = null; try { Class.forName( "org.gjt.mm.mysql.Driver" ); String url = "jdbc:mysql://localhost:3306/webphotogallery"; String username = "root"; String password = ""; conn = DriverManager.getConnection( url, username, password ); ps = conn.prepareStatement( "INSERT INTO Image (album_id, image_desc, image_full) VALUES( ?, ?, ? )" ); ps.setInt( 1, albumId ); ps.setString( 2, desc ); // Insert the image into the second Blob File image = new File( filename ); FileInputStream fis = new FileInputStream( image ); ps.setBinaryStream( 3, fis, ( int )image.length() ); // Execute the INSERT int count = ps.executeUpdate(); System.out.println( "Rows inserted: " + count ); } catch( Exception e ) { e.printStackTrace(); } finally { try { if( ps != null ) ps.close(); if( conn != null ) conn.close(); } catch( Exception ee ) { ee.printStackTrace(); } } } }
set CLASSPATH=.;<path-to-mysql-jdbc-drive>\mysql-connector-java-3.0.11-stable-bin.jar
And then execute it as follows:
java com.javasrc.webphotogallery.LoadImage myfile.jpg 1 "A picture of me and my friend"
If i had been successful i would have seen sth like this: "Rows inserted: 1"
But as i am not a successful one i get this error message from the command line:
"could not find or load main class com.javasrc.webphotogallery.LoadImage".
I also changed the directory to where this class resides...
Help me please.
I have 5 days with this problem...
Thanks in advanceLast edited by blertadhimitri; 02-01-2013 at 12:24 PM.
- 02-01-2013, 09:48 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: could not find or load main class com.javasrc.webphotogallery.LoadImage
When posting code please wrap it in [code] tags [/code] to retain the formatting.
Going by that classpath you should be executing this from the directory that contains the 'com' directory.
That is the root of your package structure.
This also presumes you've compiled the code into a class file...:)
I don't see where JBoss comes into this, though.
I expect that's later on?Please do not ask for code as refusal often offends.
- 02-01-2013, 12:27 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 30
- Rep Power
- 0
Re: could not find or load main class com.javasrc.webphotogallery.LoadImage
Yes I executed this from the directory that contains the "com" directory but the same thing happens...
Is there someone that can help me more about this problem??
It is totally disorienting me...
- 02-01-2013, 12:51 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: could not find or load main class com.javasrc.webphotogallery.LoadImage
And you compile the LoadJava file?
There is a LoadJava.class file in the com/javasrc/webphotogallery directory?Please do not ask for code as refusal often offends.
- 02-01-2013, 01:22 PM #5
Member
- Join Date
- Jan 2013
- Posts
- 30
- Rep Power
- 0
Re: could not find or load main class com.javasrc.webphotogallery.LoadImage
I resolved the problem of "could not find or load main class com.javasrc.webphotogallery.LoadImage" .
It was a mistake of mine when specifieng the directory but now i get another problem so i made a neq thread for that problem ...
Similar Threads
-
could not find or load main class com.javasrc.webphotogallery.LoadImage
By blertadhimitri in forum JDBCReplies: 1Last Post: 01-31-2013, 09:41 PM -
could not find or load main class com.javasrc.webphotogallery.LoadImage
By blertadhimitri in forum Advanced JavaReplies: 1Last Post: 01-31-2013, 09:40 PM -
could not find or load main class com.javasrc.webphotogallery.LoadImage
By blertadhimitri in forum Java ServletReplies: 1Last Post: 01-31-2013, 09:38 PM -
could not find or load main class | cannot manually locate class file
By Holden Caulfield in forum New To JavaReplies: 1Last Post: 11-29-2012, 09:46 AM -
Could not find or load main class
By kkid in forum New To JavaReplies: 4Last Post: 10-15-2012, 04:47 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks