Just started learning android app develpoment.
getting error "android.content.activitynotfoundexception no activity found"
Code:-
my Android Mainfest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gtctest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".StartingPointActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.GTC.STARTINGPOINTACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
and my Splash Screen.java
package com.example.gtctest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class SplashScreen extends Activity {
#Override
protected void onCreate(Bundle splashBundle) {
// TODO Auto-generated method stub
super.onCreate(splashBundle);
setContentView(R.layout.splash);
Thread timer=new Thread() {
public void run() {
try {
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent openStartingPointActivityIntent=new Intent("com.GTC.STARTINGPOINTACTIVITY");
startActivity(openStartingPointActivityIntent);
}
}
};
timer.start();
}
#Override
protected void onPause() {
super.onPause();
finish();
}
}
error:-
09-15 14:31:19.587: E/AndroidRuntime(1088): FATAL EXCEPTION: Thread-123
09-15 14:31:19.587: E/AndroidRuntime(1088): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.GTC.STARTINGPOINTACTIVITY }
09-15 14:31:19.587: E/AndroidRuntime(1088): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
09-15 14:31:19.587: E/AndroidRuntime(1088): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
09-15 14:31:19.587: E/AndroidRuntime(1088): at android.app.Activity.startActivityForResult(Activity.java:3190)
09-15 14:31:19.587: E/AndroidRuntime(1088): at android.app.Activity.startActivity(Activity.java:3297)
09-15 14:31:19.587: E/AndroidRuntime(1088): at com.example.gtctest.SplashScreen$1.run(SplashScreen.java:28)
Cant't figure out what is wrong.please help to solve this issue
And one more question
In android mainfest the name action name can be anything or it has to be path from package like "com.GTC.classname"
you have two application tags in your manifest. change it to one with both activities
please modify your manifest like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gtctest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".SplashScreen"
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=".StartingPointActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.GTC.STARTINGPOINTACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
ps: in android mainfest, the action name can be anything, but we used to make it like "com.xxx.intent.action.XXX".
Try this way,hope this will help you to solve your problem.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gtctest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<activity
android:name=".StartingPointActivity"
android:label="#string/app_name"/>
</manifest>
public class SplashScreen extends Activity {
#Override
protected void onCreate(Bundle splashBundle) {
// TODO Auto-generated method stub
super.onCreate(splashBundle);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(SplashScreen.this,StartingPointActivity.class);
startActivity(intent);
finish();
}
},3000);
}
#Override
protected void onPause() {
super.onPause();
}
}
Create Intent Like Following...
Intent intentname =new Intent(SplashScreen.this,StartingPointActivity.class);
startActivity(intentname);
Change in your AndroidManifest.xml File..
You have defined two <application> tag....
remove that and change it to following..
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gtctest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- add new activities like this -->
<activity
android:name=".StartingPointActivity"
android:label="#string/app_name" >
<!-- if your activity in different package you can define like this... (xx.xxx is your package name define your package name there..)
<activity
android:name="xx.xxx.StartingPointActivity"
android:label="#string/app_name" >
-->
</application>
</manifest>
Related
I'm trying to use onConfigurationChanged to detect screen rotation.
Activity
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public void onConfigurationChanged(#NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Toast.makeText(getApplicationContext(), "Screen is rotated!", Toast.LENGTH_SHORT).show();
Log.i("ROTATEAPP", "Screen is rotated...");
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.ScreenRotate"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
I rotated the device (Pixel 3 running Android 12) a few times, and didn't see any Toast or log entry. What's wrong here?
<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>
Timer is not working. after few second it should goto another activity
public class intro extends Activity {
int count=0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.intro);
final Toast tosta = Toast.makeText(this, String.valueOf(count+"."), Toast.LENGTH_SHORT);
final Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
count++;
if(count == 5){
Intent app = new Intent("com.jasrajcomputers.MainActivity");
startActivity(app);
}
tosta.show();
}
}, 1000, 1000);
}}
but after 5 sec app unfortunately has stopped.
manifext.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jasrajcomputers"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:theme="#style/noactionbarvirat"
android:label="#string/app_name" >
<activity
android:name=".intro"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.jasrajcomputers.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.jasrajcomputers.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
MY LOGCAT:
07-12 12:46:38.979: E/AndroidRuntime(14495): FATAL EXCEPTION: Timer-0
07-12 12:46:38.979: E/AndroidRuntime(14495): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.jasrajcomputers.MainActivity }
07-12 12:46:38.979: E/AndroidRuntime(14495): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1697)
07-12 12:46:38.979: E/AndroidRuntime(14495): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1492)
07-12 12:46:38.979: E/AndroidRuntime(14495): at android.app.Activity.startActivityForResult(Activity.java:3388)
07-12 12:46:38.979: E/AndroidRuntime(14495): at android.app.Activity.startActivityForResult(Activity.java:3349)
07-12 12:46:38.979: E/AndroidRuntime(14495): at android.app.Activity.startActivity(Activity.java:3584)
07-12 12:46:38.979: E/AndroidRuntime(14495): at android.app.Activity.startActivity(Activity.java:3552)
07-12 12:46:38.979: E/AndroidRuntime(14495): at com.jasrajcomputers.intro$1.run(intro.java:72)
07-12 12:46:38.979: E/AndroidRuntime(14495): at java.util.Timer$TimerImpl.run(Timer.java:284)
Just have
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:theme="#style/noactionbarvirat"
android:label="#string/app_name" >
<activity
android:name=".intro"
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" >
</activity>
</application>
Use Explicit intents
Intent app = new Intent(intro.this, MainActivity.class);
Remove
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.jasrajcomputers.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.jasrajcomputers.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Update :
Timer is not required here. You can use a Handler instead.
Quoting docs
Explicit intents specify the component to start by name (the
fully-qualified class name). You'll typically use an explicit intent
to start a component in your own app, because you know the class name
of the activity or service you want to start. For example, start a new
activity in response to a user action or start a service to download a
file in the background.
Use a Handler
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
Intent app = new Intent("com.example.MainActivity");
startActivity(app);
}
}, 5000);
Try to replace this code :
Intent app = new Intent("com.jasrajcomputers.MainActivity");
With this code :
Intent app = new Intent(intro.this,MainActivity.class);
Note :
MainActivity must be define in AndroidManifest.xml
I have a splash screen with a timer that runs for 3 seconds. After the 3 seconds it is supposed to auto load another activity called Dashboard. I made a new class that I want to have load after the splash screen called WelcomeSplash. I changed the classes in the splash screen from Dashboard to WelcomeSplash and the app force closes and the logcat says it has a null point exception. Here is the snip of code from the splash class and logcat snip.
02-13 23:18:46.826: E/AndroidRuntime(2475): FATAL EXCEPTION: main
02-13 23:18:46.826: E/AndroidRuntime(2475): java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.magicbuddy.gamble/com.magicbuddy.gamble.welcomeSplash}:
java.lang.NullPointerException
02-13 23:18:46.826: E/AndroidRuntime(2475): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
Here is the snip of the Splash code
startActivity(new Intent(Splash.this, welcomeSplash.class));
When I change the welcomeSPlash.class to Dashboard.class the app does not force close. Here is the welcomeSplash Activity,
public class welcomeSplash extends Activity implements OnClickListener {
Button btnskip;
Button btnplay;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
btnskip =(Button) findViewById(R.id.btnSkip);
btnskip.setOnClickListener(this);
btnplay =(Button) findViewById(R.id.btnOk);
btnplay.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnSkip:
Intent a = new Intent(welcomeSplash.this, Dashboard.class);
startActivity(a);
break;
case R.id.btnOk:
Intent i = new Intent(welcomeSplash.this, Profile.class);
startActivity(i);
break;
}
}
}
THe manifest is copied below too.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.magicbuddy.gamble"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.magicbuddy.gamble.Splash"
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="com.magicbuddy.gamble.welcomeSplash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.magicbuddy.gamble.Dashboard" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.magicbuddy.gamble.Dashboard"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.magicbuddy.gamble.MainActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.magicbuddy.gamble.Player"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.magicbuddy.gamble.Menu"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.magicbuddy.gamble.Popup"
android:label="#string/title_activity_popup" >
</activity>
</application>
</manifest>
Remove this code from your menifest
<intent-filter>
<action android:name="com.magicbuddy.gamble.Dashboard" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
example using roboguice.
This code get ClassCastException.
public class MainActivity extends RoboActivity{
#InjectView(R.id.text)
TextView name;
#InjectView(R.id.imageView1)
ImageView imageView;
Drawable icon;
#InjectResource(R.string.app_name)
String myName;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
all jar files are already included.
My manifest.xml is here..
find this here.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.roboguice"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.roboguice.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>
</application>
</manifest>
no changes in manifest.xml.
if required then say.
Try this way
<application
android:name="roboguice.application.RoboApplication" // UPDATE HERE
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
Add this following line in application tag in AndroidManifest.xml
android:name="roboguice.application.RoboApplication"
#see [More details][1] http://code.google.com/p/roboguice/source/browse/roboguice/src/main/java/roboguice/application/RoboApplication.java?r=b6ae6aeaf9417826a2359fd779814af839557ca1