In my Android Studio project, I found lots of "Error:(38, 45) error: unreported exception IOException; must be caught or declared to be thrown" errors. How do I resolve these errors?
This is the code I have:
public class ActivityHome extends Activity {
private final static String QUEUE_NAME = "AndroidJava";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("xx.xx.xx.xx");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello Java!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
System.out.println(" [x] Sent '" + message + "'");
channel.close();
connection.close();
}
}