-5
    1. While executing below code i'm getting NullpointerException.

        public class SftpConn
            {
            public List<String> searchableFields(String sheetName, int column) {
                    if (sheet == null) {
                        sftpConnect();
                    }
                    List<String> test=null;
                    sheet = wb.getSheet(sheetName);
                    int rowcount = sheet.getLastRowNum();
                    for (int i = 1; i <= rowcount; i++) {
                        Row r = CellUtil.getRow(i, sheet);
                        key = CellUtil.getCell(r, column).getStringCellValue();
                        System.out.println("key = "+key);
                        test.add(key);
                    }
                    return test;
                }
            }
      

2.Below is the main class where i'm calling "searchableFields" from searchableFields

3.every time i'm seeing same error please suggest"

                public class MyTest {
                public static void main(String[] args) {
                    // TODO Auto-generated method stub
                    SftpConn sftp = new SftpConn();
                    List<String> list = sftp.searchableFields("Searchable Fields", 0);
                    System.out.println(list);
                }
            }
            
            
  1. Below is my Out put please suggest that what could be the issue.

              Session connected  true
    
                 key = Check Document
    
    
                 Exception in thread "main" java.lang.NullPointerException
                     at com.brcc.tool.Configuration.SftpConn.searchableFields(SftpConn.java:120)
                     at com.brcc.tool.Configuration.MyTest.main(MyTest.java:10)
    
     *
    
Soumya Ranjan Das
  • 125
  • 1
  • 1
  • 11
  • 2
    Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) (hint: `test` is never initialized.) – Salem Jul 08 '20 at 18:34

2 Answers2

0

You have not initliazed the list, replace:

List<String> test=null;

with:

List<String> test=new ArrayList<>();
user1708042
  • 1,561
  • 15
  • 20
0

Initialize test with an implementation of the List interface.

List <String> test = new ArrayList<>();
frianH
  • 6,710
  • 6
  • 17
  • 42