How to declare a new activity in Android manifest? - java

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);

Related

How to change Activity Priority in Android Studio

Iam trying to add Splash screen to my existing Android Project, which is not MainActivity.Java, but by default Android Studio is executing MainActivity.Java first, So I want to change the Activity Priority so that my SplashActivity.Java will execute first and later Activity's will follow after the Splash Screen.
Make splash activity your launcher activity instead of Main Activity in Android Manifest.
<activity
android:name=".ui.splash.SplashActivity"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
modify your AndroidManifest.xml like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.circlefil.reactivetrip">
<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=".MainActivity"/>
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
You need to add IntentFilter in you splash screen activity and from splash screen activity you have to link your main activity using Intent.
Add following code to your splash screen activity.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
How ever keeping an entire activity is not the best way to create splash screen. See this for more info: Here
To Start activity first you need to make it Launcher Activity in AndroidManifest.xml file.
<activity
android:name=".StartingActivityName">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Activity cannot be cast to android.app.Application

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.

Crashing App Fatal exception main [duplicate]

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>

android "use $ instead of ." produce cannot resolve symbol

In my manifest. with the new SDK, it requires me to replace my android:name paths with the warning:
use $ instead of . for inner classes(or use only lowercase letters in package name)
This is one of my activities:
<activity
android:name=".Activities.LoginActivity" >
</activity>
and it suggest me to replace it with
<activity
android:name=".Activities$LoginActivity" >
</activity>
The problem is that this produce the following:
Cannot resolve symble Activities
So, what I have to do? I just ignore the alert or I have to replace it someway else?
EDIT:
here is the source of activities folder:
app.java.personal.pier.myapp.Activities
this is my entire manifest, I don't think it should be need but just in case it is here :)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="personal.pier.myapp" >
<uses-permission android:name="andorid.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:supportsRtl="true" >
<activity
android:name=".Activities.SplashScreenActivity"
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=".Activities.LoginActivity" >
</activity>
<activity
android:name=".Activities.HomePageActivity" >
</activity>
<activity
android:name=".Activities.FoodAddActivity" >
</activity>
<activity
android:name=".Activities.FoodManagementActivity" >
</activity>
<activity
android:name=".Activities.FoodDetailsActivity" >
</activity>
<activity
android:name=".Activities.EatingSuntActivity" >
</activity>
<activity
android:name=".Activities.EatingDetailsActivity" >
</activity>
<activity
android:name=".Activities.EatingAddActivity" >
</activity>
<activity android:name=".Activities.SportAddActivity" >
</activity>
</application>
</manifest>
The most likely problem appeared because you are using upper case in your package name.

Exported activity does not require permission

So, I am going over tutorials to learn android and I have the bellow code which is giving me this warning in the title and the app will not run for some reason any help?
This is the code:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.learn.tam.Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SPLASH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.learn.tam.StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
The part that is showing the error is the Second
< activity
You are advertising that any application on the device can start com.example.learn.tam.StartingPoint, and Lint is warning you that this is insecure.
Most likely, you do not need that <intent-filter> -- you only usually need those for activities that you are expecting other apps to start. Hence, the simplest way to get rid of this warning is to delete that <intent-filter> and use an explicit Intent when you start that activity (e.g., new Intent(this, StartingPoint.class)).
If you elect to keep the <intent-filter>, for whatever reason, please:
Do not use android.intent.action. as the prefix for your own invented actions -- come up with something else, such as com.example.learn.tam.
Add android:exported="false" to the <activity> element to say that, despite the fact that you have an <intent-filter>, you are not expecting other applications to start your activity

Categories