yogi ta dev

Greenhorn
+ Follow
since Nov 25, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by yogi ta dev

Hi,
I am not clear with the concept of classloder and reflection.Is it necessary to
load classes before u can apply refection on the class?
And also for loading classes do u have to set any classpath ..I am trying to use URLClassLoader but it dosen't seem to work..
thnks
yogita
16 years ago
Hi,
This is the error message java.lang.NullPointerException
and the error is at the following line:115
which is
File[] cf=new File[list.size()];

Thanks,
yogita
16 years ago
Hi,
I have some problem in the path.I am supposed to pick .java files from the src directory..The src directory could be under C:/hw_4/src ,the user should be able to select at runtime..But I am able to pick only the .java files from src directly under C: which is C:/src..The following is the code..I have tried too much but can't come up with a solution..Really appreciate any help..The error that I get is nullpointerexceptio..

package MainPk;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.filechooser.*;
import java.io.File;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileView;
import java.util.*;
import Model.*;

public class TestFrame extends JFrame
{
private String description = " ";
private ArrayList extensions = new ArrayList();
public File[] f1;
public File[] cf1;
ArrayList list;
public File[] f;
public String namepath,newpath,parentdir;
public File name;
private JLabel label;
public JFileChooser fc = new JFileChooser();
public ExtensionFileFilter filter = new ExtensionFileFilter();
String str[];
int count=0;

public TestFrame()
{
setTitle("FileChooser");
setSize(400,400);
JMenuBar menuBar=new JMenuBar();
setJMenuBar(menuBar);
JMenu menu=new JMenu("File");
JMenuItem openItem=new JMenuItem("Open");
menu.add(openItem);
openItem.addActionListener(new FileOpenListener());
JMenuItem exitItem=new JMenuItem("Exit");
menu.add(exitItem);
exitItem.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
});
label = new JLabel();
Container contentPane = getContentPane();
contentPane.add(label);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
menuBar.add(menu);
}
private class FileOpenListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
//fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
ExtensionFileFilter filter = new ExtensionFileFilter();
filter.addExtension("java");
filter.setDescription("Java files");
fc.setFileFilter(filter);
int result = fc.showOpenDialog(TestFrame.this);
if(result == JFileChooser.APPROVE_OPTION)
{
name =fc.getSelectedFile();
String name1=name.getName();
File file=new File(name1);

namepath= name.getAbsolutePath();
cf1=visitAllDirsAndFiles(file);

}
}
}

public File[] visitAllDirsAndFiles(File dir)
{

if (dir.isDirectory())
{
File[] children = dir.listFiles();
list =new ArrayList(100);
for (int i=0;i<children.length; i++)
{
f1 = children[i].listFiles();

for(int j=0;j<f1.length;j++)
{

list.add(f1[j]);

}
}

}
else
dir=dir.getParentFile();
File[] cf=new File[list.size()];
list.toArray(cf);
return cf;

}


class ExtensionFileFilter extends FileFilter
{
public void addExtension(String extension)
{
if(!extension.startsWith("."))
extension = "." + extension;
extensions.add(extension.toLowerCase());
}
public void setDescription(String aDescription)
{
description = aDescription;
}
public String getDescription()
{
return description;
}
public boolean accept(File f)
{
if(f.isDirectory()) return true;
String name=f.getName().toLowerCase();
for(int i=0;i<extensions.size();i++)
if(name.endsWith((String)extensions.get(i)))
return true;
return false;
}
}
}
Thanks,
yogita
16 years ago
thanks,
I got the solution.
16 years ago
Hi,
This is the piece of code.I am getting Null pointer exception when I return cf.When I tried to print the length of cf ,the value returned was 30 where as there are not so many elements stored.Please help..

public File[] f1= new File[30];
public File[] cf=new File[30];
int count=0;
for(int j=0;j<f1.length;j++)
{
cf[count]=f1[j];
count++;
}
return cf;
Thanks..
16 years ago
I have an array which has all class files names.I have to check if they exist in classes directory and load them,then use refection to get methods
in each of the classes.

Thanks,
yogita
16 years ago
I have an array which has all class files names.I have to check if they exist in classes directory and load them,then use refection to get methods
in each of the classes.

Thanks,
yogita
16 years ago
Hi ,
I have to load .class files .Can anyone pls let me know how to do it?
I have tried searching ,but could not find.
Thanks,
yogita
16 years ago
Hi ,
I have to load .class files .Can anyone pls let me know how to do it?
I have tried searching ,but could not find.
Thanks,
yogita
16 years ago