What version of hadoop are you using?

On 5/14/11 9:37 AM, "Lạc Trung" <trungnb3...@gmail.com> wrote:

Hello everybody !



This exception was thrown when I tried to copy a file from local file to
HDFS.

This is my program :

***************************************************************

import api.InterfaceAudience;

import java.awt.event.ActionListener;

import java.io.IOException;

import java.awt.event.ActionEvent;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.swing.*;

import org.apache.hadoop.conf.Configured;

import org.apache.hadoop.io.IOUtils;

import org.apache.hadoop.fs.FileSystem;

import org.apache.hadoop.fs.Path;

import org.apache.hadoop.fs.FSDataOutputStream;



@InterfaceAudience.Private

public class CopyFile extends Configured {



  private JFrame form;

  private JTextField box1;

  private JTextField box2;

  private JButton sobr;

  private JButton debr;

  private JButton copy;

  protected FileSystem fs;





  public CopyFile() {

    init();

  }



  private void copyFromStdin(Path dst, FileSystem dstFs) throws IOException
{

    if (dstFs.isDirectory(dst)) {

      throw new IOException("When source is stdin, destination must be a
file.");

    }

    if (dstFs.exists(dst)) {

      throw new IOException("Target " + dst.toString() + " already
exists.");

    }

    FSDataOutputStream out = dstFs.create(dst);

    try {

      IOUtils.copyBytes(System.in, out, getConf(), false);

    }

    finally {

      out.close();

    }

  }



  void copyFromLocal(Path[] srcs, String dstf) throws IOException {

    Path dstPath = new Path(dstf);



    FileSystem dstFs = dstPath.getFileSystem(getConf());

    if (srcs.length == 1 && srcs[0].toString().equals("-"))

      copyFromStdin(dstPath, dstFs);

    else

      dstFs.copyFromLocalFile(false, false, srcs, dstPath);

  }



    public static void main(String args[])

    {

        try{

            CopyFile fs=new CopyFile();

            fs.form.setVisible(true);

        }catch(Exception e) {System.out.println(e);}

    }



    private void init()

    {



        form=new JFrame();

        form.setTitle("Copy File");

        form.setBounds(100, 100, 450, 300);

        form.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        form.getContentPane().setLayout(null);





        box1=new JTextField();

        box1.setEditable(false);// cho phep thay doi hay khong ?--> khong.

        box1.setText("Source File Path");

        box1.setBounds(10, 89, 196, 20);

        form.getContentPane().add(box1);

        box1.setColumns(10);





        box2=new JTextField();

        box2.setEditable(false);// cho phep thay doi hay khong ?--> khong.

        box2.setText("Destination File Path");

        box2.setBounds(10, 155, 196, 20);

        form.getContentPane().add(box2);

        box2.setColumns(10);





        sobr=new JButton("Browse");

        ActionListener act1=new ActionListener() {

                        String str;

                                                public void
actionPerformed(ActionEvent arg0) {



                                                                JFileChooser
fc = new JFileChooser();




fc.setFileSelectionMode(JFileChooser.FILES_ONLY);



                                                                if
(JFileChooser.APPROVE_OPTION == fc.showOpenDialog(form)) {




box1.setText(fc.getSelectedFile().getPath());

                                    this.str=fc.getSelectedFile().getPath();

                                                                }



                                                }

                                };



                sobr.addActionListener(act1);

                sobr.setBounds(249, 88, 89, 23);

                form.getContentPane().add(sobr);







        debr=new JButton("Browse");

        ActionListener act2=new ActionListener() {



                                                public void
actionPerformed(ActionEvent arg0) {



                                                                JFileChooser
fc = new JFileChooser();




fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);



                                                                if
(JFileChooser.APPROVE_OPTION == fc.showOpenDialog(form)) {


box2.setText(fc.getSelectedFile().getPath());



                                                                }

                                                }

                                };

                debr.addActionListener(act2);

                debr.setBounds(249, 154, 89, 23);

                form.getContentPane().add(debr);



        copy =new JButton("Copy");


        ActionListener act3=new ActionListener() {

            public void actionPerformed(ActionEvent arg0){

                String str1=box1.getText();

                String str2=box2.getText();

                Path[] path=new Path[1];

                path[0]=new Path(str1);

                try {

                    copyFromLocal(path, str2);

                } catch (IOException ex) {


Logger.getLogger(CopyFile.class.getName()).log(Level.SEVERE, null, ex);

                }





            }

        };

                 copy.addActionListener(act3);

                 copy.setBounds(100 , 200 , 89, 23);

                 form.getContentPane().add(copy);



        }

    }

****************************************************************************

And the output is :

****************************************************************************


Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

        at
org.apache.hadoop.fs.FileSystem.getDefaultUri(FileSystem.java:103)

        at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:95)

        at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:180)

        at org.apache.hadoop.fs.Path.getFileSystem(Path.java:175)

        at learnsocket.CopyFile.copyFromLocal(CopyFile.java:60)

        at learnsocket.CopyFile$3.actionPerformed(CopyFile.java:152)

        at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)

        at
javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)

        at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)

        at
javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)

        at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)

        at java.awt.Component.processMouseEvent(Component.java:6267)

        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)

        at java.awt.Component.processEvent(Component.java:6032)

        at java.awt.Container.processEvent(Container.java:2041)

        at java.awt.Component.dispatchEventImpl(Component.java:4630)

        at java.awt.Container.dispatchEventImpl(Container.java:2099)

        at java.awt.Component.dispatchEvent(Component.java:4460)

        at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)

        at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)

        at java.awt.Container.dispatchEventImpl(Container.java:2085)

        at java.awt.Window.dispatchEventImpl(Window.java:2478)

        at java.awt.Component.dispatchEvent(Component.java:4460)

        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)

        at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)

        at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)

        at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)

        at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

        at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)



********************************************************************************


Please tell me what my problem is and how to fix it.



Thanks so much ^^ !



--
Nguyễn Bá Trung
SHSV : 20083535
SĐT    : 01216259222
Email  : trungnb3...@gmail.com

Reply via email to