When I try to create a new activity it says NullPointerException
It says IDE fatal when I tried look into the error from the event log
Oops!! I was doing it wrong
There is no Issue if I create the new Activity this way.
You may not have created entry for intent-filter in manifest.If you are creating both java and layout file separately without directly creating a activity.
Create a java file say Main.java
use following code :
public class Main extends AppCompatActivity{
#Override
protected void onCreate(Bundle savedState)
{
super.onCreate(savedState);
setContentView(R.layout.your_layout);
}
and in manifest add after application tag
<activity
android:name=".Main">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Follow the below steps:
Open the folder bin under the directory where you installed your Android Studio.
Open the file "idea.properties" and open it with Notepad++/UltraEdit/other_edit_tools.
Add "disable.android.first.run=true" as the final line and save the file.
Because you have another layout/activity/menu/or other things.
I faced the same issue, it inserts the activity into Manifest but never creates a new file.
Try these things
Try to use another name activity/fragment/...
Delete other unnecessary things/files e.g. from drawable, files created previously in other directories as well.
Try this following things...
Try to Build Your Project.
Try to Clean your Project.
If not work then Restart Project/Android Studio.
If still not work Then try to Add Activity with Right click and Add
New Java Class.
And check SDK is proper
and let me know what happens.
Hope this will helps...(:
Related
Well, just like the title suggests, every activity within my application is being added to the app drawer.... Im really hating this new ADT. First it was a problem with the app name appearing as the first activity name, now all the activities are showing up on the application list. If I go to uninstall it only shows 1. Anyone else having this problem and has figured out a work around?
for future cases specifically you can change in the android manifest under :
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
change to:
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
This will remove the activities' icon from the app drawer. As the OP says: sometimes the wizard puts this in the manifest for you.
Ok, figured it out... Everytime you create a new activity through the adt wizard (New -> Android Activity) it creates the code in your manifest for you.... the problem is that it added intent filters to it as well. Just remove those and they dont show up.... stupid adt.
I know when I am using IntelliJ as my IDE for Android programming, there is a box you can check when using the wizard to create a new Activity that says "Mark as start-up Activity".
Be aware of these types of things because that is what caused me to have the same problem you had Shaun.
I wouldn't completely erase the intent filters, simply have only the Activity you want as the "start-up" Activity marked as the "Launcher" in the Manifest file. All other Activities get "Default".
I have an application using the Google maps - until the moment it works fine. But now when I want to click a button in order to add functionality over the map I have problems.
I managed to visualise the button on the screen, also it works on click - it shows a toast correctly. But my aim is to start a new activity (having his own layout) - looking and reading tones of tutorials and stuff here is what I have :
//the Add Button in the upper right corner
Button addBookmark = (Button) findViewById(R.id.Button);
addBookmark.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View mapView) {
Intent addBookmarkIntent = new Intent(GoogleMapsApp.this, LocationBookmaker.class);
startActivity(addBookmarkIntent);
}
});
Also I've edited the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<activity android:name=".LocationBookmarker"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
...
</manifest>
No matter what I try I always get the "The Application GoogleMapsApp (process google.maps.app) has stopped unexpectedly. Please try again." with the only "Force close" option.
I've been trying since two days now - and in a lot of examples in the Internet other say it should be working like this. I cannot see where could be my mistake.
Maybe in the starting of the intent, or the manifest or where...?
According to the exception, the class it's looking for is 'LocationBookmaker', but in your manifest you have 'LocationBookmarker' (notice the 'r'). That may be your problem.
I don't know what the problem you get is but a tip is to run the "Dalvik Debug Monitor" (ddms) on your computer, with that you can capture all exceptions in your application and see exaclly what the error is (most of the time).
You find the ddms in the tools directory of your android installation, if you run windows its a bat file, ddms.bat, that you just run from cmd.
/Viktor
hey guys
i change the package name in manifest file so that i have a separate package for all the activities and it is giving me error classnotfoundexception when although the classes shown in log cat are present in my source folder.
i even then changed the package name to previous one. and still it is giving me the same error.
In your manifest file, if the package address of the activity contains a relative namespace address (starting with a dot) like this:
<activity
android:name=".addr.MainActivity"
</activity>
you can get it to work by changing it to the full address like this:
<activity
android:name="com.pkg.addr.MainActivity"
</activity>
I always get an error when I run my created application and based on my research I haven't registered my Activity in the manifest. How can I register a new activity in AndroidManifest.xml?
Assuming you're using Eclipse,
Goto your Android Manifest, goto the Applications Tab (at the bottom), click on "Add", Choose Activity. On the right, next to Name: Click on Browse, to get a list of available activities, just add it and you're set! :)
You could right way just edit the Manifest XML aswell. It's upto you.
<activity android:name="com.kl.android.ReadSMS.ViewSMS" />
just use the class name after '.'
like the following
<activity android:name=".ViewSMS"/>
In Android Studio, Go to AndroidManifest.xml file and use
<activity android:name="YourPackageName.ClassName">
For example,
<activity android:name="com.android.favoritetoys.MainActivity">
For More List of activity attributes in AndroidManifest.xml
i have created 4 activities in eclipse now i want to run activity 1, 2,3 ,4 repectively one by one in emulator for testing.
can any one guide me how can i run those all???
when i press run button it only runs first activity.
any help would be appriciated.
You could try startActivityForResult but you may need to possibly modify your program your applications to handle this.
I would suggest using one of the android sdk tools called am (activity manager).
In the adb shell:
# am start -n package-name/activity-1-name
# am start -n package-name/activity-2-name
# am start -n package-name/activity-3-name
# am start -n package-name/activity-4-name
Go to the AndroidManifest.xml and cut
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
from the Main Activity. Then paste it into the Activity that you want to start.
To Run A specific Activity First
Change the Activity Name In the setContentView within the Main Activity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Your_Activity_Name);
}
public void onClick(View v) {
Intent i;
i = new Intent(this, YourActivity1.class);
startActivity(i);
i = new Intent(this, YourActivity2.class);
startActivity(i);
i = new Intent(this, YourActivity3.class);
startActivity(i);
i = new Intent(this, YourActivity4.class);
startActivity(i);
}
Android SDK includes the JUnit framework for writing unit tests. You can use the package android.test packages to run activities under JUnit. It may be overkill for what you want but eventually you may need this functionality.
References:
http://junit.sourceforge.net/
http://mylifewithandroid.blogspot.com/2008/11/junit-in-android.html
Go to the Android Manifest file under your workspace root and double click on it to open. Go to the AndroidManifest.xml tab and change the name of the first activity to whatever activity you want to launch at run. Also make sure you rename that first activity to the other activity so ADT doesn't throw errors. Basicall, switch their names in the xml file. I had to do it because I wanted to test each activity individually before linking them. Let me know if you have any other question.