-
Notifications
You must be signed in to change notification settings - Fork 0
/
CO 03 - Question 01.txt
46 lines (35 loc) · 1.6 KB
/
CO 03 - Question 01.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
------------------------------------------------------------------- XML Code -------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".ExceptionActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exception Activity"/>
</LinearLayout>
------------------------------------------------------------------- Java Code -------------------------------------------------------------------
package com.example.optionsmenunavigation;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
public class ExceptionActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exception);
try{
int n1=0, n2=0;
int a= n1/n2;
Toast.makeText(getApplicationContext(), "The value is : "+a, Toast.LENGTH_SHORT).show();
}
catch (Exception e){
Toast.makeText(getApplicationContext(), "The caught exception is : "+e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}