android.content.ActivityNotFoundException: Unable to find explicit activity class - android

public class ListViewActivity extends AppCompatActivity
{
ListView lv;
String[] ListItems={"AutoCompleteTextViewActivity","CheckboxActivity","EditTextActivity","ListViewActivity","ProgressBarActivity","RadioButtonActivity","RatingBar2Activity","RatngBarActivity","SeekBarActivity","SpinnerActivity","SwitchActivity","TextViewActivity"};
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view);
lv=(ListView)findViewById(R.id.listView1);
ArrayAdapter ad=new ArrayAdapter(ListViewActivity.this,android.R.layout.simple_list_item_1,ListItems);
lv.setAdapter(ad);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent i = new Intent(ListViewActivity.this, ListItems[position].getClass());
startActivity(i);
}
});
}
}
i am current learning android studio.i made an app through which i can open my previously created apps by choosing them from a listview widget.it shows an error in the intent line.please tell me where i've have gone wrong.
MY MANIFEST FILE
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.user.re1">
<application
android:allowBackup="true"
android:banner="#mipmap/ic_launcher_round"
android:icon="#mipmap/ic_launcher_round"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".TextViewActivity" />
<activity android:name=".EditTextActivity" />
<activity android:name=".RadioButtonActivity" />
<activity android:name=".CheckboxActivity" />
<activity android:name=".RatngBarActivity" />
<activity android:name=".RatingBar2Activity" />
<activity android:name=".ProgressBarActivity" />
<activity android:name=".SeekBarActivity" />
<activity android:name=".SwitchActivity" />
<activity android:name=".SpinnerActivity"/>
<activity android:name=".AutoCompleteTextViewActivity">
</activity>
<activity android:name=".ListViewActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Add your activity name to your manifest file
<activity android:name=".ListViewActivity"></activity>

Related

animated splash screen doesn't appear

In this project I tried to make an animated splash screen which will appear before going to the main activity, but after I execute, the splash screen does not appear but instead goes directly to the main activity.
how to fix this?
this is my splash activity class
private ImageView container;
private AnimationDrawable animationDrawable;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash)
container = findViewById(R.id.iv_icons);
container.setBackgroundResource(R.drawable.mysplash_animation);
animationDrawable = (AnimationDrawable) container.getBackground();
}
#Override
protected void onResume() {
super.onResume();
animationDrawable.start();
checkAnimationStatus(50, animationDrawable);
}
private void checkAnimationStatus(final int time, final AnimationDrawable animationDrawable) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
if (animationDrawable.getCurrent() != animationDrawable.getFrame(animationDrawable.getNumberOfFrames() - 1))
checkAnimationStatus(time, animationDrawable);
else finish();
}
}, time);
}
}
and this is my manifest.xml
<application
android:allowBackup="true"
android:exported="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.NoActionBar">
<activity android:name=".SplashActivity"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
You have to change this in your manifest(you have to give launcher activity to splashActivity)
<application
android:allowBackup="true"
android:exported="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.NoActionBar">
<activity android:name=".SplashActivity">
// below code you have to add //
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
//Remove from here//
</activity>
</application>
Set your Splash Activity as the Launcher activity:
<activity android:name=".MainActivity"></activity>
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Please provide intentfilter to SplashActivity
<application
android:allowBackup="true"
android:exported="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.NoActionBar">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
</activity>
</application>

ActivityNotFoundExceptionstarted appearing out of nowhere

Before my application was working fine. I just created a new class (within the same package) and also declared it in the manifest, still I get a ActivityNotFoundException and sometimes NoClassDefFoundException.
TestActivity.java
public class TestActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.order_summary);
}
}
Activity_NewOrder.java
public class Activity_NewOrder extends Activity
try {
//Also tried Intent intent = new Intent(Activity_NewOrder.this, TestActivity.class);
Intent intent = new Intent(getApplicationContext(), TestActivity.class);
startActivity(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mypackage">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".Activities.Activity_OrderSummaryNew"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape" />
<activity
android:name=".Activities.Activity_Login"
android:configChanges="orientation"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activities.Activity_Orders"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape" />
<activity
android:name=".Activities.Activity_NewOrder"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape" />
<activity
android:name=".Activities.Activity_OrderHistory"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape" />
<activity android:name=".Activities.TestActivity" />
</application>
</manifest>

I am not able to switch to another Activity from a ListView activity

I have 3 activities in my application.
Start activity(with a timer of 5 sec after that Menu activity appears)
Menu activity
Main activity
The Menu Activity has a listview adapter.
I want to get the Main activity after clicking an item form the list but it is not switching to Main Activity after clicking.
Here is my Menifest file
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="THE APP"
android:theme="#style/AppTheme" >
<activity
android:name=".start"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter android:label="MAIN">
<action android:name="androphlie.myfirst.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="MENU" >
<intent-filter
android:label="MENU" >
<action android:name="androphlie.myfirst.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
The Menu.java is as follows
public class Menu extends ListActivity {
String classes[]={"MainActivity","example1","example2","example3","example4","example5"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String listitem=classes[position];
try {
Class ourClass = Class.forName("com.androfile.myfirst."+listitem);
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
}catch (ClassNotFoundException e){e.printStackTrace();
}
}}
I am new to android and not able to find out the problem in code
In your onListItemClick listener ,package name com.androfile.myfirst you entered is incorrect compared to manifest file com.androphlie.myfirst
Change
Class ourClass = Class.forName("com.androfile.myfirst."+listitem);
to
Class ourClass = Class.forName("com.androphlie.myfirst."+listitem);

ListActivity not working

I'm creating a menu where all of my activity will be on the list, and whenever i clicked an activity from that list, it should start that activity.
here is my menu.java
public class Menu extends ListActivity
{
String classnames[] = {"MainActivity","example1","example2","example3",
"example4","example5","example6","example7","example8","example9","example10"};
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this,android.R.layout.simple_list_item_1,classnames));
}
protected void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
String classClicked = classnames[position];
try
{
Class ourclass = Class.forName("android.intent.action."+classClicked);
Intent intent = new Intent(Menu.this,ourclass);
startActivity(intent);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
}
}
here is my manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
It don't have any error but my MainActivity doesn't start even when I clicked it.
Here's what it looks like:
Use getListView().setOnItemClickListener instead of onListItemClick. Why? to be honest i also dont know, but it solved my problem.
You must declare all your activities in AndroidManifest.xml otherwise it won't work. Your updated manifest file should look like this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".example1"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example2"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example3"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example4"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example5"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example6"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example7"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example8"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example9"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example10"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
Menu.java
public class Menu extends ListActivity
{
String classnames[] = {"MainActivity","example1","example2","example3",
"example4","example5","example6","example7","example8","example9","example10"};
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this,android.R.layout.simple_list_item_1,classnames));
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, final int position, long l) {
String classClicked = classnames[position];
try {
Class ourclass = Class.forName("android.intent.action."+classClicked);
Intent intent = new Intent(getApplicationContext(),ourclass);
startActivity(intent);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
}
});
}
protected void onListItemClick(ListView l, View v, int position, long id)
{
/*super.onListItemClick(l, v, position, id);
String classClicked = classnames[position];
try
{
Class ourclass = Class.forName("android.intent.action."+classClicked);
Intent intent = new Intent(Menu.this,ourclass);
startActivity(intent);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}*/
}
}
And now everything should work.
You must register the other activities in your manifest, just like the mainactivity. Otherwise Android wont start them.

Unable to find explicit activity class error

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exampl.fitindya"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="20" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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>
<!-- Entry for RegisterActivity.class -->
<activity android:name=".RegisterActivity"
android:label="Register New Account"></activity>
</application>
Don't know why this error is appearing and application crashes. please help guys.can there be any problem anywhere else
here is my class file
public class MainActivity extends ActionBarActivity {
Button login_b1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
TextView registerScreen = (TextView) findViewById(R.id.link_to_register);
// Listening to register new account link
registerScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Switching to Register screen
Intent i = new Intent(getApplicationContext(), RegisterActivity.class);
startActivity(i);
}
});
}
}
Place this code below the register Activity. I guess that should be the error
<intent-filter>
<action android:name="android.intent.action.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

Categories

Resources