I added another button to my app but now the app crashes on start up. Here is the code that I added in, when I block it out the app runs fine.
btnnext.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent("com.com.com.addtask"));
}
});
}
I think it might be a problem with the manifest so here is the manifest too (and this is only a playing around app so dont hassle me about the package being com.com.com)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.com.com"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name" android:permission="android.permission.INTERNET">
<activity android:name=".HelloWorldActivity"
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=".addtask"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.com.com.addtask" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
And this might be helpful too:
05-16 21:21:55.446: E/AndroidRuntime(581): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.com.com/com.com.com.HelloWorldActivity}: java.lang.NullPointerException
Have you declared the new button that you have added within the activity?
Button btnnext = (Button)findViewById(R.id.myNewButton);
If you don't do this and set a listener it will throw the nullpointer error.
First identify the button from xml to activity using
Button b = (Button) findViewById(R.id.btnNext);
Related
So this is something really strange that i cannot figure out.
I am developing a normal educational application on eclipse that is just supposed to have some exercises.
Everything was going pretty well, i had one of my exercises completed, then i decided to add a second exercise (at a new activity, like the first one)
So i added a new activity (Exercise3), with nothing in it, only the default textview that eclipse adds and i created an button that leads to that activity from my main menu.
The code is this, and is exactly the same code (different names off course) that works for my 1st exercise and perfectly changes forms.
button2 = (Button) findViewById(R.id.button2);
// Capture button clicks
button2.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// Start NewActivity.class
Intent myIntent = new Intent(MainMenu.this,
Exercise3.class);
startActivity(myIntent);
}
});
There is absolutely no error in the log, and the app runs perfectly, but when i press button 2 to open the new activity i created, my application crashes.
Again, eclipse shows nothing, the code is exactly the same with my first button to activity which works perfect, but i don't know whats happening with this one.
There is only something strange though, on the new activity i add the standard "Hello World" textview that always is there is replaced by one saying "Error loading". In the mainmenu activity also where i had forgotten that standard textview, now it also says "Error loading" instead of "hello world".
(Just checked out this was done by my partner in this app from the strings.xml).
The xml is the following:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.main.pirateisland.Exercise3" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
I noticed that the id is missing from the textview, i tried adding it manualy, or completely erasing it and same problem, the application crashes when i try to go to that form from my button.
There is absolutely not error.warning whatsoever from eclipse which makes this quite confusing for me.
I guess there is something wrong with the xml, but i just cant find what. Maybe i changed something without noticing?
Also tried cleaning the project, restarting eclipse etc, nothing helps and the problem persists.
EDIT: Adding the manifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.main.pirateisland"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="22" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MainMenu"
android:label="#string/app_name"
android:theme="#style/MyTheme" >
<intent-filter>
<action android:name="com.main.pirateisland.MainMenu" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".LoginScreen"
android:label="#string/title_activity_login_screen"
android:theme="#style/MyTheme" >
<intent-filter android:label="#string/app_name" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Exercise1"
android:label="#string/title_activity_exercise1"
android:theme="#style/MyTheme" >
</activity>
<activity
android:name=".SplitActivity"
android:configChanges="keyboardHidden|orientation"
android:label="#string/title_activity_split"
android:screenOrientation="portrait"
android:theme="#style/MyTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/title_activity_main"
android:screenOrientation="landscape"
android:theme="#style/MyTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Exercise3"
android:label="#string/title_activity_exercise3" >
</activity>
</application>
</manifest>
Change context where activity will change.
Intent myIntent = new Intent(SecondActivity.this, Exercise3.class);
Or
Intent myIntent = new Intent(getApplicationContext(), Exercise3.class);
Remove the action attribute <action android:name="com.main.pirateisland.MainMenu" /> from the intent filter of .MainMenu
<activity
android:name=".MainMenu"
android:label="#string/app_name"
android:theme="#style/MyTheme" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
And add the category DEFAULT intent filter to .Exercise3
<activity
android:name=".Exercise3"
android:label="#string/title_activity_exercise3" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Here's the problem guys, first i tried to run my application with Launch default activity as launch action (Run Configurations --> Android --> Launch action), the logcat kept telling me that it can't find the launcher activity and the application wouldn't even start, problem is i defined my launcher activity in the manifest file, but it's like it's not reading it at all.
So i tried to launch the splash activity by specifically telling it to run it through run configurations, it did launch but during the transition to the next activity it crashed again, the logcat says no activity found to handle intent, which again, I defined the way I did in other applications and worked alright there. Plase help it's a nightmare.
Here's the code for the MainActivity:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread timer = new Thread()
{
public void run(){
try{
sleep(6000);
} catch (InterruptedException e){
e.printStackTrace();
} finally {
Intent openStarting = new Intent("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);
}
}
};
timer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
And Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="totaltrainer.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<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="totaltrainer.com.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutPlace"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutPlace" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutHome"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutHome" />
</intent-filter>
</activity>
<activity
android:name=".WorkoutGym"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.WorkoutGym" />
</intent-filter>
</activity>
</application>
</manifest>
use "totaltrainer.com.WORKOUTGYM" and so on
and below use this
<category android:name="android.intent.category.DEFAULT" />
Problem 1
logcat kept telling me that it can't find the launcher activity and
the application wouldn't even start
In your Manifest file, change below
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="totaltrainer.com.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
as
<activity android:name="MainActivity">
<!-- This activity is the main entry, should appear in app launcher -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
What happens when you define this Action and Category ?
The ACTION_MAIN action indicates this is the main entry point and does not expect any intent data.
The CATEGORY_LAUNCHER category indicates that this activity's icon should be placed in the system's app launcher. If the element does not specify an icon with icon, then the system uses the icon from the element.
These two must be paired together in order for the activity to appear in the app launcher.
Problem 2
the logcat says no activity found to handle intent
Your Manifest declaration seems fine.
In your activity class, change
Intent openStarting = new Intent("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);
as
Intent openStarting = new Intent();
openStarting.setAction("totaltrainer.com.WorkoutPlace");
startActivity(openStarting);
I am having an issue when trying to go from the main screen of my app to display the data that i have collected in my SQLiteDatabase. Here is my Application manifest...
I have tried switching the Main.java file from LAUNCHER to DEFAULT and the opposite for the database java file to make it open when it is run and i can get it to display that class that way but not using the button that I have in the Main.java file that is for changing to see the data.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.innovativesolutions.gpsareafinder"
android:versionCode="2"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="14" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.innovativesolutions.gpsareafinder.Main"
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.innovativesolutions.gpsareafinder.Locationdbview"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Here is the section in my Main.java file that has to do with the Intent where I am trying to call the Location database java file.
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bcalculate:
area();
break;
case R.id.bclear:
clear();
break;
case R.id.bloc:
Intent in = new
Intent("com.innovativesolutions.gpsareafinder.Locationdbview");
startActivity(in);
break;
I think the error is something simple in my manifest or where I try to use the Intent to switch views...If anyone has any ideas please help. Thanks!
Change your second activity in the manifest to:
<activity
android:name="com.innovativesolutions.gpsareafinder.Locationdbview"
android:label="#string/app_name" >
</activity>
You don't need any filters there.
Change the call in your firstActivity to:
startActivity(new Intent(this, Locationdbview.class));
You can also try this in Main.java
Class myclass =Class.forName("com.innovativesolutions.gpsareafinder.Locationdbview");
Intent in=new Intent(Main.this,myclass);
startActivity(in);
In Manifest.xml :
<activity android:name=".Locationdbview" ></activity>
I am currently developing an Android 2.2 application that needs to resume to the main activity from another one.
I am using this code:
private void btnAbort_OnClick(View v)
{
startActivity(new Intent(v.getContext(), Main.class));
finish();
}
but when I call the method (by clicking a button) I get the following error:
02-02 20:05:19.117: E/dalvikvm(864): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
What is going wrong here?
Edit:
Manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.game"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".Main"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SingleplayerActivity"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="eu.game.SINGLEPLAYERACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
If you're resuming to the main activity and not just starting it, there's no reason to call startActivity. Just finish the current Activity, and Android will pop it off the Activity Stack and go to the previous one. For more information, you can read up on the Android Activity Lifecycle in the docs.
Trying passing this instead of v.getContext().
Is there any long running operation launched by your code ?
I fixed the problem by creating a new thread for the second activity. Thanks for all your help.
I'm trying to create a very simple custom intent example. I've searched for this error and none of the forums have answers that work for me. Here are my files:
public class DemoImplicit extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void whenButtonIsClicked(View view) {
Intent intent = new Intent("com.example.action.NEW_ACTION"); //<<<<<<<
intent.addCategory("android.intent.category.DEFAULT"); //<<<<<<<
// Intent intent = new Intent("android.intent.action.VIEW");
// intent.addCategory("com.example.MY_CATEGORY");
startActivity(intent); //<<<<<<<
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demos" android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".SatisfyIntent" android:label="#string/app_name">
<intent-filter>
<!-- action android:name="android.intent.action.VIEW" / -->
<!-- category android:name="com.example.MY_CATEGORY" / -->
<action android:name="com.example.action.NEW_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
These two separate files are in two different Eclipse projects, but I make sure to load the project containing the intent-filter onto the emulator before loading the file containing the startActivity call onto the emulator. In any case, I always get an ActivityNotFoundException.
What am I doing wrong?
P.S. Here's the AndroidManifest.xml file for the project containing DemoImplicit.java:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demos"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".DemoImplicit"
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>
<uses-sdk android:minSdkVersion="9" />
</manifest>
Fisrtly you shuld ensure that your AndroidManifest.xml file must have defined the DemoImplicit Activity in this.
As like this:<activity android:name=".DemoImplicit"/>
Also in your code you have aspecified the SatisfyIntent as a launcher Activity
<activity android:name=".SatisfyIntent" android:label="#string/app_name">
But here it seems like you have nothing like this in your Java Code.
So the Bottom line is that: Activity which you want to run must have defined in your AndroidManifest.xml file.