When I start the application, it force close.
This is the LogCat:
java.lang.RuntimeException: Unable to instantiate application com.blocktrekacademy.officialblocktrek.Authentication: java.lang.ClassCastException: com.blocktrekacademy.officialblocktrek.Authentication cannot be cast to android.app.Application
[UPDATED] : This is my AndroidManifest.xml:
...
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".Authentication"
android:label="#string/title_activity_authentication"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is my Authentication.java
package com.blocktrekacademy.officialblocktrek;
import ...
public class Authentication extends AppCompatActivity {
...
First, remove android:name=".Authentication" property in <application> tag.
Your Authentication class is an Activity, not an Application. So, you have to declare it as such:
<application>
...
<activity android:name=".Authentication"
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
That intent-filter declares the Activity as the "main" activity, so it will be launched when your app starts.
Related
My code was compiling before but stopped working and is giving this error
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed with multiple errors, see logs
log
java.lang.RuntimeException: Activity name cannot be empty. at
com.android.tools.idea.model.MergedManifest$ActivityAttributes.(MergedManifest.java:579)
at
com.android.tools.idea.model.MergedManifest.syncWithReadPermission(MergedManifest.java:418)
at
com.android.tools.idea.model.MergedManifest.access$000(MergedManifest.java:55)
at
com.android.tools.idea.model.MergedManifest$1.run(MergedManifest.java:331)
at
com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:945)
at
com.android.tools.idea.model.MergedManifest.sync(MergedManifest.java:328)
at
com.android.tools.idea.model.MergedManifest.getActivities(MergedManifest.java:464)
at
com.android.tools.idea.run.activity.DefaultActivityLocator.lambda$computeDefaultActivity$97(DefaultActivityLocator.java:78)
at
com.intellij.openapi.project.DumbService$1.run(DumbService.java:89)
my manifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:header=".MyApplication"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:header=".ui.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:header="android.intent.action.MAIN" />
<category android:header="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:header=".ui.ResponseActivity"
android:label="#string/title_item_detail"
android:parentActivityName=".ui.MainActivity"
android:theme="#style/AppTheme.NoActionBar">
<meta-data
android:header="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity" />
</activity>
</application>
what could be the cause of this?
Use this for your main activity because name field is required to identify an activity not the header so replace every header with name field
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
instead of this
<intent-filter>
<action android:header="android.intent.action.MAIN" />
<category android:header="android.intent.category.LAUNCHER" />
</intent-filter>
So it will
<activity
android:name=".ui.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and do the same for other activities too
You have to write android:name=".ui.activityName" in your activity tag of manifest file for each of the activity.
Hope this helps!
I created a splash screen in my application suddenly when I ran the code it stopped. I created a splash screen in my code then it will redirect you to the menu. Is there something wrong with the android manifest xml?
Here's my manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kenneth.rusa">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".WelcomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.action.LAUNCHER">
</category>
</intent-filter>
</activity>
<activity android:screenOrientation="landscape" android:name=".Play">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
And this is the splash class code:
package com.example.kenneth.rusa;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
/**
* Created by Kenneth on 8/6/2016.
*/
public class WelcomeActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcomeactivity);
RunMe runme = new RunMe();
Thread t = new Thread(runme);
t.start();
}
class RunMe implements Runnable {
public void run() {
SystemClock.sleep(3000);
Intent intent = new Intent(WelcomeActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
}
}
Please remove following lines from activities other than splash
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
Nvm I fixed it by changing the manifest file
Here's the updated code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kenneth.rusa">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.NoActionBar">
<activity android:screenOrientation="landscape" android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.default" />
</intent-filter>
</activity>
<activity android:name=".WelcomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:screenOrientation="landscape" android:name=".Play">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.default"/>
</intent-filter>
</activity>
</application>
Ok
I have manifest
<application
android:name=".App"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".ui.authorization.AuthActivity"
android:noHistory="true">
</activity>
<activity android:name=".ui.callsigns.SelectCallsignActivity"
android:launchMode="singleTop">
</activity>
<activity android:name=".ui.order.waitorder.WaitOrderActivity"
android:launchMode="singleTop">
</activity>
<activity android:name=".ui.balance.BalanceActivity"
android:noHistory="true"
/>
<activity android:name=".ui.splash.SplashActivity"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ui.order.gotorder.GoogleMapsActivity"/>
<activity android:name=".ui.order.gotorder.OrderDetailsActivity"
android:launchMode="singleTask"/>
<service android:name=".location.ServiceForLocation"/>
<service android:name=".network.newsocket.NewSocketService"/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key"/>
<meta-data
android:name="io.fabric.ApiKey"
android:value="db0dc6f3ae8099a148926812fca7bd6cc29b4f4b"/>
</application>
...
Next start WaitOrderActivity
Intent intent = new Intent(getBaseContext(), WaitOrderActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
startActivity(intent);
Next from callback but in WaitOrderActivity I start OrderDetailsActivity
After all I call again startActivity(WaitOrderActivity) or OrderDetailsActivity.this.finish, anyway I will be in WaitOrderActivity again.
Trouble: in second time I see by logs what OrderDetailsActivity started, but I doesn't see that on the screen. I still see WaitOrderActivity. Why?
This question already has answers here:
...have you declared this activity in your AndroidManifest.xml
(3 answers)
Closed 7 years ago.
Hi I have tried to add a class to my tabbed fragment and it is throwing an error, I thought at first that I was being stupid because I had not added the activity to the manifest but after I did it didn't work. How do you add an activity top the manifest and is the below error throwing this exception
ON: main
Process: com.androidbelieve.drawerwithswipetabs, PID: 14861
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidbelieve.drawerwithswipetabs/com.androidbelieve.drawerwithswipetabs.BradClass}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1793)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1515)
at android.app.Activity.startActivityForResult(Activity.java:4026)
at android.app.Activity.startActivityForResult(Activity.java:3973)
at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:829)
at android.support.v4.app.Fragment.startActivity(Fragment.java:897)
at com.androidbelieve.drawerwithswipetabs.LeagueOne$1.onItemClick(LeagueOne.java:41)
at android.widget.AdapterView.performItemClick(AdapterView.java:339)
at android.widget.AbsListView.performItemClick(AbsListView.java:1544)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3721)
at android.widget.AbsListView$3.run(AbsListView.java:5660)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6837)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
This is how I wrote my activity
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<activity
android:name=".LeagueOne"
android:label="leagues"></activity>
<activity
android:name="com.androidbelieve.drawerwithswipetabs.BradClass"
android:label="leagues"></activity>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Change your manifest to:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"/>
<activity
android:name=".LeagueOne"
android:label="leagues"/>
<activity
android:name="com.androidbelieve.drawerwithswipetabs.BradClass"
android:label="leagues">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Your manifest.xml has some wrong.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name">
</activity>
<activity
android:name=".LeagueOne"
android:label="leagues"></activity>
<activity
android:name="com.androidbelieve.drawerwithswipetabs.BradClass"
android:label="leagues">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
If you want to use MainActivity as luncher,you can move intent-filter to MainActivity block.
Change your manifest to the given below, you put activity under activity thats the main problem all activity should be declared separate.
<application
android:allowBackup="true"
android:icon="#mipmap/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>
<activity
android:name=".LeagueOne"
android:label="leagues"></activity>
<activity
android:name="com.androidbelieve.drawerwithswipetabs.BradClass"
android:label="leagues"></activity>
</application>
Add Activity in Manifest this way:
<activity
android:name="com.androidbelieve.drawerwithswipetabs.BradClass"
android:label="leagues">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I've followed the Android docs in adding a new activity to the manifest, but when I try to navigate to the class using a button click event I get a null pointer exception.
I gather from this that the class isn't being recognized as being present. To debug this I substituted the class name for .SearchTree and it navigated succesfully.
Can anyone see where I've made a mistake in the manifest?
<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>
<activity
android:name=".SearchResult">
</activity>
<activity
android:name=".SearchTree"
android:label="#string/app_name" >
</activity>
</application>
This is the error in full detail below:
E/AndroidRuntime(3508): java.lang.RuntimeException: Unable to start activity ComponentInfo{ie.gmit.computing/ie.gmit.computing.SearchResult}: java.lang.NullPointerException
`
The cause of the null pointer exception turned out to be because I left out the below line of code from the onCreate();
setContentView(R.layout.activity_search_result);