unreported exception despite of try-catch block
You have declared that the method throws an exception - which it doesn't:
public String fileNotFoundExTest() throws FileNotFoundException {
Just change to:
public String fileNotFoundExTest() {
unreported exception twitter4j.TwitterException; must be caught or declared to be thrown
You need to handle the TwitterException that the code of the initializer block can throw, by wrapping it within a try-catch. Adding throws TwitterException
in the main
method will not solve the problem, because the exception is not thrown within the main method.
{
try {
ConfigurationBuilder cb = new ConfigurationBuilder();
List <Status> status = twitter.getHomeTimeline();
for(
Status st:status)
{
System.out.println(st.getUser().getName() + "----------" + st.getText());
}
} catch(TwitterException ex) {
... // handle exception
}
}
if this is a console application, you can change the code to use a CommandLineRunner
(see https://www.baeldung.com/spring-boot-console-app).
Related Topics
Is There a Destructor for Java
Where Is Array's Length Property Defined
Connecting to Remote Url Which Requires Authentication Using Java
Java Error: Implicit Super Constructor Is Undefined for Default Constructor
Illegalmonitorstateexception on Wait() Call
Why Does Inetaddress.Isreachable Return False, When I Can Ping the Ip Address
Why Are Filenames in Java the Same as the Public Class Name
How to Map an Entity Field Whose Name Is a Reserved Word in JPA
How to Switch Between Frames in Selenium Webdriver Using Java
Tomcat 10.0.4 Doesn't Load Servlets (@Webservlet Classes) with 404 Error
How Does Autowiring Work in Spring
Using Switch Statement with a Range of Value in Each Case
Group a List of Objects by an Attribute
How to Print Binary Tree Diagram in Java
Jsp Tricks to Make Templating Easier
How to Specify Jackson to Only Use Fields - Preferably Globally