Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Unable to instantiate the class to use the method of that class

  1. #1
    Junior Member
    Join Date
    Jan 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Unable to instantiate the class to use the method of that class

    Hello,

    In JAVA program, I am trying access a method from a Excel class but I am unable to instantiate the Excel class to access the method defined in Excel class.
    Eclipse shows error as "The constructor Excel(String) is not visible." Please suggest how to instantiate the class to access the members of the class.

    Please suggest.

    import com.atlassian.jira.rest.client.api.domain.Attachment;
    import com.atlassian.jira.rest.client.api.domain.Issue;
    import com.bwc.testcase.TestcaseKeyword;
    import com.bwc.util.JIRA;
    import com.bwc.util.excel.Excel;
    import com.bwc.util.excel.ExcelUtil;
    public class TestExcel extends TestcaseKeyword {
     
    	Excel test = new Excel("abc");
     
    			public void getattachments() throws EncryptedDocumentException, IOException {
     
    			JIRA jira = JIRA.getInstance();    
     
    			Issue message = jira.getIssue("TEST-123");
    			Iterator<Attachment> iter = message.getAttachments().iterator();
    			   while (iter.hasNext()){
    		        	 Attachment attachmentIter = iter.next();
    		        	 String obj =  attachmentIter.getFilename();
    		             System.out.println(obj);
    		             test.loadExcel("C:\\Tools\\Automation\\JiraUpload\\jiraattachment\\data\\UploadAttachment.xlsx").getCellValue(0, 0);
     
    		             }
     
    		}
     
    	}

     
    public class Excel 
    {
    	private String filePath;
    	private Map<String,Integer> currentRow; // the current row
    	private Workbook workbook;
    	private String currentSheet; //the current sheet name
     
    	DataFormatter objDefaultFormat;
    	FormulaEvaluator objFormulaEvaluator;
     
    	private Excel(String file) {
    		this(file,null);
    	}
     
    	private Excel(String file,String sheetName) 
    	{
    		this.filePath=file;
    		this.currentSheet=sheetName;
    		this.currentRow=new HashMap<String,Integer>();		
    		currentRow.put(sheetName, 1);	
    		this.objDefaultFormat= new DataFormatter();
    		objFormulaEvaluator=null;
     
    		try {
    			FileInputStream inputStream=new FileInputStream(filePath);
    			if(filePath.endsWith(".xlsx")) {
    				this.workbook =new XSSFWorkbook(inputStream);
    				this.objFormulaEvaluator= new XSSFFormulaEvaluator((XSSFWorkbook)workbook);
    			} else {
    				this.workbook = new HSSFWorkbook(inputStream);
    				this.objFormulaEvaluator= new HSSFFormulaEvaluator((HSSFWorkbook)workbook);
    			}
    			if(StringUtil.isEmpty(sheetName)) {
    				sheetName=workbook.getSheetName(0);
    			}
    		} catch (Exception e) {
    			throw new ActionFailedException("Failed to load file:"+filePath);
    		}
     
    	}
     
    	public static Excel loadExcel(String file,String sheetName) {
    		return new Excel(file,sheetName);
    	}
    Last edited by ashlel; January 14th, 2021 at 05:04 PM. Reason: Adding code

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    23,617
    Thanks
    53
    Thanked 2,529 Times in 2,480 Posts

    Default Re: Unable to instantiate the class to use the method of that class

    Please post the source code for the classes you are having problems with.
    Be sure to wrap all code in code tags.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Call class method from another class
    By NewbieJavaProgrammer in forum Object Oriented Programming
    Replies: 1
    Last Post: November 21st, 2012, 06:56 AM
  2. create a test class (main method) to start(run) the class in Java
    By curious725 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 1st, 2012, 03:21 AM
  3. Can't instantiate custom class
    By mwr76 in forum Object Oriented Programming
    Replies: 5
    Last Post: October 18th, 2011, 05:43 PM
  4. Could not instantiate bean class
    By Sheval in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 21st, 2011, 03:40 PM
  5. Accessing a method of one class in another class
    By Sai in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 23rd, 2010, 04:06 PM