HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Wed Aug 25, 2010 8:21 pm Post subject: fucking eclipse, need some help |
|
|
Solved: FUCK ME! I figured it out. the folder i was using to test on my netbook (which existed) didn't exist on my desktop. So i was getting a null error and therefore the program was crashing before main was executed. Really a frustrating thing but i fixed it and decided to leave it up for other people to laugh at me. Also posted the rest of the code incase someone wants to see how to download an image from google.
Ok so i developed an app on my netbook and transferred the project to my desktop. The app worked perfect on netbook. When i try to run the code on my desktop, i get an error saying main class not found. I checked the classpath and it is pointing to the correct class to look for main in and main is declared.
I figured i would just create a new project and c/p the source. did a test with the new project and just ran a simple println (and it worked) but as soon as i imported the source, it again said main class not found. Everything is properly named / setup.
edit: this is my source code.
| Code: |
//imageFetcher.java
import java.io.File;
import javax.swing.*;
import BreezySwing.*;
public class imageFetcher extends GBFrame
{
public static DefaultListModel model;
public static JList list;
public static File folder = new File("C:\\phonebackup");
public static File[] listOfMovies = folder.listFiles(), listOfImages, toDownload = new File[listOfMovies.length];
public imageFetcher()
{
list = addList(1,1,1,1);
model = (DefaultListModel)list.getModel();
File[] listOfFiles2 = folder.listFiles();
int t = 0, g = 0, a = 0;
for(int i = 0; i < listOfFiles2.length; i++)
{
if(listOfFiles2[i].isFile() && !listOfFiles2[i].isHidden())
{
if(listOfFiles2[i].getName().contains(".jpg"))
{
a++;
}
}
}
listOfImages = new File[a];
for(int i = 0; i < listOfFiles2.length; i++)
if(listOfFiles2[i].isFile() && !listOfFiles2[i].isHidden())
{
if(listOfFiles2[i].getName().contains(".jpg"))
{
listOfImages[t] = listOfFiles2[i];
t++;
}
else
{
listOfMovies[g] = listOfFiles2[i];
g++;
}
}
int q = 0;
for(int i = 0; i < listOfMovies.length; i++)
{
if(!isInList(listOfMovies[i], listOfImages))
{
toDownload[q] = listOfMovies[i];
model.addElement(toDownload[q].getName());
q++;
}
}
}
public void listDoubleClicked(JList obj, String text2)
{
if(obj == list)
{
String path = toDownload[0].getPath();
path = path.substring(0, path.indexOf(toDownload[0].getName()));
for(int i = 0; i < toDownload.length; i++)
{
String text = toDownload[i].getName();
String temp = text.substring(0, text.indexOf('.'));
// fetch x;
try {
// x = new fetch(temp, path);
// x.operate();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
public static boolean isInList(File f, File[] list)
{
String temp = f.getName(), temp2;
temp = temp.substring(0, temp.indexOf('.'));
for(int i = 0; i < list.length; i ++)
{
temp2 = list[i].getName();
temp2 = temp2.substring(0, temp2.indexOf('.'));
if(temp.equals(temp2))
return true;
}
return false;
}
public static void main(String[] args)
{
imageFetcher win = new imageFetcher();
win.setSize(350,600);
win.setVisible(true);
}
}
|
| Code: |
//fetch.java
import java.net.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import javax.swing.*;
import java.io.*;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageOutputStream;
import javax.swing.JLabel;
public class fetch {
static String path, title;
public fetch(String title2, String path2) throws Exception
{
title = convertSpaces(title2);
System.out.println(title);
path = path2;
}
public void operate() throws Exception
{
boolean found = false;
//create the url
String urlString = "http://www.google.com/images?q="+ title + "%20Movie%20Cover" + "&biw=1440&bih=707";
URL url = new URL(urlString);
//create a http connection to make the program look like a browser to google
HttpURLConnection httpcon = (HttpURLConnection) url.openConnection();
httpcon.addRequestProperty("User-Agent", "Mozilla/4.76");
BufferedReader reader = new BufferedReader(new InputStreamReader(httpcon.getInputStream()));
//parse line looking for first instance of imgurl (for the first image found)
String line = "";
while(((found != true && (line = reader.readLine()) != null)))
{
if(line.contains("imgurl"))
{
int[] temp = new int[2];
temp[0] = line.indexOf("imgurl=") + 7;
temp[1] = line.indexOf("&imgrefurl", temp[0]);
line = line.substring(temp[0], temp[1]);
System.out.println(line);
found = true;
}
}
downloadImage(line);
System.out.println(title + " downloaded");
}
private static void downloadImage(String url) throws Exception
{
System.out.println(url);
try{
URL u = new URL(url);
Image image2;
image2 = ImageIO.read(u);
title = title+".jpg";
File file = new File(path + title);
System.out.println(file.getAbsolutePath());
BufferedImage image = toBufferedImage(image2);
if(!ImageIO.write(image, "jpg", file))
System.out.println("error");
}
catch(Exception e)
{
System.out.println("Google yeilded no results!");
}
}
private static BufferedImage toBufferedImage(Image src)
{
int w = src.getWidth(null);
int h = src.getHeight(null);
int type = BufferedImage.TYPE_INT_RGB;
BufferedImage ret = new BufferedImage(w,h,type);
Graphics2D g2 = ret.createGraphics();
g2.drawImage(src, 0, 0, null);
g2.dispose();
return ret;
}
private static String convertSpaces(String input)
{
String temp = "";
temp = input.replaceAll(" ", "%20");
return temp;
}
}
|
_________________
|
|