First of all I think You had copied the Code Form Mykong
It's shown that you MainActivity.java
is in package com.mkyong.android
But in your manifest file your main package name is com.example.toast
.You haven't mention any about files in com.mkyong.android
in your manifest
file
Are you sure you are using tow package names ?? if so
So there are two options
OPTION 1
In your log it clearly says com.example.toast.MainActivity
is not found
You must change the package of MainActivity.java
to com.example.toast
<activity
android:name="com.example.toast.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This will remove the RuntimeException
OPTION 2
The second option is to change in manifest
file
<activity
android:name="com.mkyong.android.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Note That if you application contains more than one package names you must specify the package name along with along with activity names in manifest file
eg : android:name="com.mkyong.android.MainActivity"
where com.mkyong.android
is package name and MainActivity
is file name
I Prefer you to choose OPTION 1
To display you toast you can use
Toast.makeText(MainActivity.this, "Button is clicked", Toast.LENGTH_LONG).show();
Here MainActivity.this
is the parameter for context
You can also use this
Toast.makeText(getApplicationContext(), "Button is clicked",Toast.LENGTH_LONG).show();
If you are beginner This Android Boot Camp Series Tutorial might help you