lundi 20 avril 2015

Cant find out why i'm getting null pointer exception, can anybudy help me?

My task is to upload image & display path of the image to the user, i have the following snippet but its not showing the path of the image, instead it is throwing null pointer exception in at the location of storage path, though i put generic as default path

  try {
            String storagePath ="generic";
            //String storagePath ="";
            if(storagePath!= null)
            {
            if (fileType.equalsIgnoreCase("emailTemplateImagePathUrl")
                    || fileType.equalsIgnoreCase("images"))
                storagePath = configurationSettings
                        .getEmailTemplateImagePathUrl();
            else if (fileType.equalsIgnoreCase("profileImagePathUrl"))
                storagePath = configurationSettings.getProfileImagePathUrl();
            else if (fileType.equalsIgnoreCase("imagePathUrl"))
                storagePath = configurationSettings.getImagePathUrl();
            else if (fileType.equalsIgnoreCase("postsImagePathUrl"))
                storagePath = configurationSettings.getPostsImagePathUrl();
            else if (fileType.equalsIgnoreCase("mantrasImagePathUrl"))
                storagePath = configurationSettings.getMantrasImagePathUrl();
            else if (fileType.equalsIgnoreCase("zodiacSignImagePathUrl"))
                storagePath = configurationSettings.getZodiacSignImagePathUrl();
            else if (fileType.equalsIgnoreCase("assetsBaseURL"))
                storagePath = configurationSettings.getAssetsBaseURL();
            else if (fileType.equalsIgnoreCase("assetsFolderName"))
                storagePath = configurationSettings.getAssetsFolderName();
            else if (fileType.equalsIgnoreCase("imagesFolderName"))
                storagePath = configurationSettings.getImagesFolderName();
            else if (fileType.equalsIgnoreCase("templeAssetsPrimaryFolderName"))
                storagePath = configurationSettings
                        .getTempleAssetsPrimaryFolderName();
            else if (fileType.equalsIgnoreCase("templeGalleryFolderName"))
                storagePath = configurationSettings
                        .getTempleGalleryFolderName();
            else if (fileType.equalsIgnoreCase("servicesFolderName"))
                storagePath = configurationSettings.getServicesFolderName();
            else if (fileType.equalsIgnoreCase("nearByFolderName"))
                storagePath = configurationSettings.getNearByFolderName();
            else if (fileType.equalsIgnoreCase("thumbnailsFolderName"))
                storagePath = configurationSettings.getThumbnailsFolderName();

            //String folderName = "C:\\Users\\Anupd\\workspace2\\Devalayam\\WebContent\\" + storagePath + "\\" + fileName;
            String folderName = "C:\\Users\\Anupd\\workspace2\\Devalayam\\WebContent\\" + storagePath + "\\" + fileName;
            System.out.println(storagePath);
            System.out.println(folderName);
            }
            //String uploadFileLocation = folderName + storagePath + fileName;
            String uploadFileLocation = storagePath ;
            System.out.println(uploadFileLocation);
            OutputStream out = new FileOutputStream(
                    new File(uploadFileLocation));

            int read = 0;
            byte[] bytes = new byte[1024];
            while ((read = uploadInputStream.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }
            uploadInputStream.close();
            out.flush();
            out.close();

            // http://ift.tt/1J2ydae
            out = null;
            System.gc();

            File file = new File(uploadFileLocation);



            mapObject.put("fileName", fileName);
            mapObject.put("fileType", fileType);

            String strLong = Long.toString(file.getTotalSpace());

            mapObject.put("fileSize",strLong);
            } catch (IOException e) {
            e.printStackTrace();
        }
        return g.toJson(mapObject);

& the op is null

C:\Users\Anupd\workspace2\Devalayam\WebContent\null\17f96f04-169b-47e4-9128-a326adfd2e1a-medium.jpeg
null

thanks in advance

Aucun commentaire:

Enregistrer un commentaire