0

i develop ecomerce site in that user can get category wise product when on home page all product display then click on image then query string pass and the detail displayed but when in same description want when data is filter by category then following error comes java.lang.NumberFormatException: null

Product Bean
     public String singledispp(int pid)
        {

          ProductTbl p=ad.searchproduct(pid);
            product_id=p.getProductId();
            return "/client/single.xhtml?faces-redirect=true&product_id="+product_id;

        }

              public String dispbycat(int cid)
        {
            CategoryTbl ct=(CategoryTbl)ad.searchcat(cid);
         category_id=ct.getCategoryId();
         return "/client/products.xhtml?faces-redirect=true&categoryId="+category_id;
        }
            public Collection<ProductTbl> getproductbyid()
        {
       Map<String,String> params =FacesContext.getCurrentInstance().
                       getExternalContext().getRequestParameterMap();
            String parameterOne = params.get("product_id");
            int foo = Integer.parseInt(parameterOne);

            return ad.getAllProductByProductid(foo);
        }

        public Collection<ProductTbl>getbycat()
        {

           Map<String,String> params =FacesContext.getCurrentInstance().
                       getExternalContext().getRequestParameterMap();
             String parameterOne = params.get("categoryId");

             int foo = Integer.valueOf(parameterOne);
             dispbycat(foo);
             return  ad.getbycategoryid(foo);
        }
Averroes
  • 4,168
  • 6
  • 50
  • 63
K...
  • 1
  • 1
  • 1
    Would you please mention the line number and indicate the line number? – Amit May 21 '18 at 10:23
  • Is it happening when you do `int foo = ...`. I'm guessing params.get("product_id") is returning null. – matt May 21 '18 at 10:24
  • when in getbycat() i give static value like return ad.getbycategoryid(3);then work fine but when i try get value from url then error comes – K... May 21 '18 at 10:26
  • The `.get("categoryId");` is returning null. – matt May 21 '18 at 10:31
  • i also pass parameter bt why null i don't know – K... May 21 '18 at 10:33
  • Hah, you guys are all very quick to provide answers, but none of you are right ;) NumberFormatException: null actually means that your string provided is not a valid number. "null" in this case has nothing to do with any value being null, it just means that the error message is null. Just debug it, and check what the value passed is – Jan Ossowski May 21 '18 at 10:33
  • i already debug but not go in this function – K... May 21 '18 at 10:36
  • Maybe you're not reaching the function you think you are? The error message is what happens when you try to call Integer.valueOf on a null. – matt May 21 '18 at 10:37
  • @matt yes, it gives the same result, but the comments above clearly say that the value is null, while this is not necessarily true, and may be misleading to the author. The way to go here is to debug, check the value passed and then draw conclusions.. K... you mean it doesn't enter the method at all? Then how come it throws an error? :) Can you paste your stacktrace? – Jan Ossowski May 21 '18 at 10:38
  • @matt again - NO. This error message happens just as well when you try to do something like Integer.valueOf("a"); Check your facts before commenting, because you are just confusing the author\ – Jan Ossowski May 21 '18 at 10:39
  • yes category id goes null bt why i already pass category id – K... May 21 '18 at 10:43
  • No, what you said is not correct. "When the value passed is null this error appears" is a correct (but misleading) fact. "This error appears when null is passed" is simply BS. This error appears for multiple reasons and thats just 1 of them. I did try to help, suggesting debugging and/or attaching stacktrace, what you do is just suggesting answers that may be totally wrong – Jan Ossowski May 21 '18 at 10:43
  • well, then you have your answer. If null is a correctly expected value, then you should use some construct like Integer foo = parameterOne == null ? null : Integer.valueOf(parameterOne); If not, then it's up to you to check why you get null, we can't say anything based on just what u pasted – Jan Ossowski May 21 '18 at 10:45
  • i use requestedscope is that valid or not – K... May 21 '18 at 10:50
  • @JanOssowski , you made a good point and offered the op some decent help. Criticizing the rest of us doesn't help OP. I never said "only" but that is irrelevant. So I should follow my own advice and ignore the fact you presume I did. – matt May 21 '18 at 10:52
  • @K... So right now when you `get("categoryId") you are getting null? Can you reduce your code down to the method that is causing the error? – matt May 21 '18 at 10:55
  • You should look in the Map<> params and see what parameters are being set. – matt May 21 '18 at 10:56

0 Answers0