I am writing a program that copy a file from a source to the desired destination.
But before that part, I encounter a problem and can not go forward.
When I select browse, the root diretories must be displayed in the list.
But I got the message
“Uncaught exception: java.lang.NullPointerException: 0”
I got that message when the program try to access the list.
What is the problem?
And what I have written is just a small part but I think the way I wrote is very complex. Does is it necessary to pass the static variable as I have written?
Please help me. Now I got headache and don’t know how to correct it.
//FileCopyMIDlet.java
package fileCopy;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class FileCopyMIDlet extends MIDlet
{
static FileCopyMIDlet fcMid;
FileCopyForm fcForm=new FileCopyForm("File Copy",this);
//FileCopyForm fcForm=new FileCopyForm("File Copy");
List objRoot = new List("Rootsssss",ChoiceGroup.IMPLICIT);
public FileCopyMIDlet()
{
objRoot.append("Text", null);
// TODO Auto-generated constructor stub
}
protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException
{
Display disp=Display.getDisplay(this);
disp.setCurrent(fcForm);
}
}
//FileCopyForm.java
package fileCopy;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.TextField;
public class FileCopyForm extends Form
{
static FileCopyForm fcForm;
TextField tfSource=new TextField("Source","",30,TextField.ANY);
TextField tfDestination=new TextField("Destination","",30,TextField.ANY);
Command cmdBrowse=new Command("Browse",Command.SCREEN,1);
Command cmdCopy=new Command("Copy",Command.SCREEN,1);
//List objRoot = new List("Rootsssss",ChoiceGroup.IMPLICIT);
public FileCopyForm(String title,FileCopyMIDlet fcMid)
{
super(title);
append(tfSource);
append(tfDestination);
addCommand(cmdBrowse);
addCommand(cmdCopy);
//setCommandListener(new CommandHandler(fcMid));
setCommandListener(new CommandHandler(fcForm,fcMid));
}
}
//CommandHandler.java
package fileCopy;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
public class CommandHandler implements CommandListener {
FileCopyForm fcForm;
FileCopyMIDlet fcMid;
public CommandHandler(FileCopyForm fcForm,FileCopyMIDlet fcMid)
{
this.fcForm=fcForm;
this.fcMid=fcMid;
}
public void commandAction(Command c, Displayable d)
{
FileThread objFileThread = null;
//String cmd = c.getLabel();
if(c.getLabel().equals("Browse"))
{
System.out.println("inside List Roots");
objFileThread = new FileThread(null,fcForm,fcMid);
}
Thread objThread = new Thread(objFileThread);
objThread.start();
}
}
//FileThread.java
package fileCopy;
import java.util.Enumeration;
import javax.microedition.io.file.FileSystemRegistry;
public class FileThread implements Runnable
{
String root;
FileCopyForm fcForm;
FileCopyMIDlet fcMid;
public FileThread(String root,FileCopyForm fcForm,FileCopyMIDlet fcMid)
{
this.root = root;
this.fcForm=fcForm;
this.fcMid= fcMid;
}
public void run()
{
//FileCopyMIDlet.fcMid.objRoot.deleteAll();
System.out.println("*****");
if(root == null)
{
System.out.println("*****");
getRoots( );
}
}
private void getRoots()
{
Enumeration en = FileSystemRegistry.listRoots();
while (en.hasMoreElements())
{
System.out.println("inside loop");
String root=(String)en.nextElement();
System.out.println("*****");
System.out.println(root);
FileCopyMIDlet.fcMid.objRoot.append(root, null);
}
}
}

New Topic/Question
Reply



MultiQuote



|