Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i have coge in java and it showin me error in the import and i did know how to fix it > /* * To

i have coge in java and it showin me error in the import and i did know how to fix it >

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package twitteruser;

import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; import javax.print.DocFlavor; import org.apache.poi.hpsf.ClassID; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory;

/** * * @author Myvin */ public class SearchCsv {

ArrayList retwet, count; ArrayList name, text; String nm1 = ""; String nm2 = ""; String nm3 = ""; String nm4 = ""; String nm5 = "";

public void search() throws Exception { count = new ArrayList<>(); retwet = new ArrayList<>(); name = new ArrayList<>(); text = new ArrayList<>();

InputStream inp = new FileInputStream("C:\\Users\\saedi\\Desktop\\algorthimass\\Twitteruser\\src\\docTweet.xlsx"); int ctr = 1; Workbook wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0); Row row = null; Cell cell = null; Cell coun = null; Cell nam = null; Cell t = null; boolean isNull = false; do { try { row = sheet.getRow(ctr); cell = row.getCell(12); coun = row.getCell(3); nam = row.getCell(11); t = row.getCell(1); retwet.add((cell.getNumericCellValue())); count.add(coun.getNumericCellValue()); name.add(String.valueOf(nam.toString())); text.add(String.valueOf(t.toString()));

ctr++; } catch (Exception e) { isNull = true; }

} while (isNull != true); inp.close();

}

public void getFereqancy() throws IOException, FileNotFoundException, InvalidFormatException { try { search(); } catch (Exception ex) { Logger.getLogger(SearchCsv.class.getName()).log(Level.SEVERE, null, ex); } ArrayList ferq = new ArrayList<>(); for (int i = 0; i < retwet.size(); i++) { ferq.add(retwet.get(i) + count.get(i));

} double top1 = 0; double top2 = 0, top3 = 0, top4 = 0, top5 = 0;

int ord1 = 0, ord2 = 0, ord3 = 0, ord4 = 0, ord5 = 0; for (int i = 0; i < ferq.size(); i++) { if (ferq.get(i) > top1) { top1 = ferq.get(i); ord1 = i; nm1 = name.get(i); }

}

for (int i = 0; i < ferq.size(); i++) { if (i != ord1 && top2 < ferq.get(i) && name.get(i) != nm1) { top2 = ferq.get(i); ord2 = i; nm2 = name.get(i); }

} for (int i = 0; i < ferq.size(); i++) { if (i != ord1 && i != ord2 && top3 < ferq.get(i) && name.get(i) != nm1 && name.get(i) != nm2) { top3 = ferq.get(i); ord3 = i; nm3 = name.get(i); }

} for (int i = 0; i < ferq.size(); i++) { if (i != ord1 && i != ord2 && i != ord3 && top4 < ferq.get(i) && name.get(i) != nm1 && name.get(i) != nm2 && name.get(i) != nm3) { top4 = ferq.get(i); ord4 = i; nm4 = name.get(i); }

} for (int i = 0; i < ferq.size(); i++) { if (i != ord1 && i != ord2 && i != ord3 && i != ord4 && top5 < ferq.get(i) && name.get(i) != nm1 && name.get(i) != nm2 && name.get(i) != nm3 && name.get(i) != nm4) { top5 = ferq.get(i); ord5 = i; nm5 = name.get(i); }

}

InputStream inp = new FileInputStream("C:\\Users\\saedi\\Desktop\\algorthimass\\Twitteruser\\src\\docTweet.xlsx"); int ctr = 1; Workbook wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0); Row row1 = null; Row row2 = null; Row row3 = null; Row row4 = null; Row row5 = null; Cell cell1 = null; Cell cell2 = null; Cell cell3 = null; Cell cell4 = null; Cell cell5 = null;

boolean isNull = false;

int c = 1; ArrayList tweets = new ArrayList<>(); //Q2 insert TOP 5 tweets on best Data Sturcure {

do { try { row1 = sheet.getRow(ord1); row2 = sheet.getRow(ord2); cell2 = row1.getCell(11); row3 = sheet.getRow(ord3); cell3 = row1.getCell(11); row4 = sheet.getRow(ord4); cell4 = row1.getCell(11); row5 = sheet.getRow(ord5); cell5 = row1.getCell(11);

if (cell1.toString() == nm1 || cell2.toString() == nm2 || cell3.toString() == nm3 || cell4.toString() == nm4 || cell5.toString() == nm5) { row1 = sheet.getRow(c); cell1 = row1.getCell(1); System.out.println(cell1);

c++; }

} catch (Exception e) { isNull = true; } } while (isNull != true); inp.close(); } System.out.println("Top1[ Name : " + nm1 + " Frequency : " + top1 + "]"); System.out.println("Top2[ Name : " + nm2 + " Frequency : " + top2 + "]"); System.out.println("Top3[ Name : " + nm3 + " Frequency : " + top3 + "]"); System.out.println("Top4[ Name : " + nm4 + " Frequency : " + top4 + "]"); System.out.println("Top5[ Name : " + nm5 + " Frequency : " + top5 + "]"); System.out.println("/////Answer2"); System.out.println("Top5 Tweets inserted on ArrayList tweets Successfull With access time :"); System.out.println("Insert:1"); System.out.println("Search:OLogN"); System.out.println("Delete: N ");

}

public void getTopID(int order) throws FileNotFoundException, IOException, InvalidFormatException {

InputStream inp = new FileInputStream("C:\\Users\\saedi\\Desktop\\algorthimass\\Twitteruser\\src\\src\\docTweet.xlsx"); int ctr = 1; Workbook wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0); Row row = null; Cell cell = null; Cell coun = null;

boolean isNull = false;

try { row = sheet.getRow(order); cell = row.getCell(8); String idd = String.valueOf(cell.getStringCellValue()); System.out.println("id" + idd);

} catch (Exception e) { isNull = true; }

inp.close();

}

ArrayList TwUser1, TwUser2, TwUser3, TwUser4, TwUser5;

public void saveTopUsersTweets() { TwUser1 = new ArrayList<>(); TwUser2 = new ArrayList<>(); TwUser3 = new ArrayList<>(); TwUser4 = new ArrayList<>(); TwUser5 = new ArrayList<>();

for (int i = 0; i < text.size(); i++) { if (name.get(i) == nm1) { TwUser1.add(text.get(i)); System.out.println(text.get(i)); } else if (name.get(i) == nm2) { TwUser2.add(text.get(i)); System.out.println(text.get(i));

} else if (name.get(i) == nm3) { TwUser3.add(text.get(i)); System.out.println(text.get(i));

} else if (name.get(i) == nm4) { TwUser4.add(text.get(i)); System.out.println(text.get(i));

} else if (name.get(i) == nm5) { TwUser5.add(text.get(i)); System.out.println(text.get(i));

}

}

}

public void insert(int userorder, String txt) { if (userorder == 1) { TwUser1.add(txt);

} else if (userorder == 2) { TwUser2.add(txt);

} else if (userorder == 3) { TwUser3.add(txt);

} else if (userorder == 4) { TwUser4.add(txt);

} else if (userorder == 5) { TwUser5.add(txt);

} }

public void searchonTopTweets(String txt) { for (int i = 0; i < text.size(); i++) { if (text.get(i).contains(txt)) { System.out.println("Found it");

}

} System.out.println("Success search");

}

public void delete(String user) { if (user == nm1) { TwUser1.remove(TwUser1.size() - 1); } else if (user == nm2) { TwUser2.remove(TwUser2.size() - 1); } else if (user == nm3) { TwUser3.remove(TwUser3.size() - 1); } else if (user == nm4) { TwUser4.remove(TwUser4.size() - 1); } else if (user == nm5) { TwUser5.remove(TwUser5.size() - 1); } }

}

the error is in this :

import javax.print.DocFlavor; import org.apache.poi.hpsf.ClassID; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory;

and the error is

run:

Exception in thread "main" java.lang.ExceptionInInitializerError

at twitteruser.Twitteruser.main(Twitteruser.java:22)

Caused by: java.lang.RuntimeException: Uncompilable source code - package org.apache.poi.hpsf does not exist

at twitteruser.SearchCsv.(SearchCsv.java:16)

... 1 more

C:\Users\Farah\AppData\Local\NetBeans\Cache\8.1\executor-snippets un.xml:53: Java returned: 1

BUILD FAILED (total time: 1 second)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

Analyze the impact of labor unions on health care.

Answered: 1 week ago

Question

Assess three motivational theories as they apply to health care.

Answered: 1 week ago

Question

Discuss the history of U.S. labor unions.

Answered: 1 week ago