ActivityNotFoundException unexpectedly - android

I am getting this error in my one activity and it is making no sense because I can go to the Calendar activity from another activity so I know i declared it correctly in the manifest
<activity android:name=".Calendar" android:label="Calendar"/>
Intent is in a Dialog selection
Intent ok = new Intent(Events.this,Calendar.class);
ok.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(ok); //ActivityNotFoundException
finish();
I can from activity A to the Calendar activity just fine then the Calendar activity has access to my Events activity but I cant go from my Events to the Calendar activity??
Ideas as to why this is?
EDIT: Update with error
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): FATAL EXCEPTION: main
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.app.notifyme/java.util.Calendar}; have you declared this activity in your AndroidManifest.xml?
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at android.app.Activity.startActivityForResult(Activity.java:2827)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at android.app.Activity.startActivity(Activity.java:2933)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at com.app.notifyme.Events$12.onClick(Events.java:318)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:873)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at android.widget.ListView.performItemClick(ListView.java:3513)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1849)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at android.os.Handler.handleCallback(Handler.java:587)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at android.os.Handler.dispatchMessage(Handler.java:92)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at android.os.Looper.loop(Looper.java:123)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at android.app.ActivityThread.main(ActivityThread.java:3839)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at java.lang.reflect.Method.invokeNative(Native Method)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at java.lang.reflect.Method.invoke(Method.java:507)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
08-24 12:53:46.951: ERROR/AndroidRuntime(3045): at dalvik.system.NativeStart.main(Native Method)

Import the correct package. I guess you are importing something like java.util.Calendar in your Events class.
If, for some reason, you need both Calendar classes (the one you wrote and the java.util one), you must put the complete path... for instance:
Intent ok = new Intent(Events.this, your.pkg.example.Calendar.class);

When you call finish() the system actually removes the activity from the stack.
This disallows you from going back to that activity.
I suggest you carefully read the Activity Lifecycle Documentation.
It should help you figure out your problem. :)
EDIT:
You should also not need that flag. Just start the activity, the system will take care of the rest.
You also do not have access to one activity from another activity. Each activity is a standalone unit that should not attempt to access other activities.
If you need to pass data between activities, use a static class/variable in a seperate class, or pass it using Intent.putExtra().

Related

My app freezes crashes when it's supposed to go to the next activity

I don't know why the app crashes whenever it's supposed to go to the next Activity. I made a practice app that works as it should when using the same format. I uploaded the files to gist.github.
The error is
1216-1216/com.example.chiozokamalu.newfreshstart E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ArrayIndexOutOfBoundsException
at com.example.chiozokamalu.newfreshstart.MainActivity.onClick(MainActivity.java:164)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
On line 164 of MainActivity.java:
questionView.setText(questions[questionIndex]); // set the text to the next question
EDIT: After Varun helped me, I get a new error which is
1307-1307/com.example.chiozokamalu.newfreshstart E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chiozokamalu.newfreshstart/com.example.chiozokamalu.newfreshstart.Results1}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.chiozokamalu.newfreshstart.Results1.onCreate(Results1.java:58)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:130)
            at android.app.ActivityThread.main(ActivityThread.java:3683)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
            at dalvik.system.NativeStart.main(Native Method)
The questions array at line no. 164 is going out of bound that means questionIndex is greater than the total length of the questions array. So you should add a check on the length before extracting value from the array.
You have added the check but after that you incremented the value so either you modify the if condition to if (questionIndex < questions.length -1)
or modify the questionIndex variable before the if condition
You are getting problem because you haven't initiated resultView9 that is why it is null and giving nullpointer, just initiatlise it as you done with other and everything is fine. You have initialised the resultView8 twice just add resultview9 over there

Peculiar android RuntimeException

I just received the wierdest looking stack trace on my Developer Console. What puzzles me is where "MArcos" came from? This was the app: https://play.google.com/store/apps/details?id=genius.mohammad.accelerometer.mouse
Try recreating the exception if you want and explain to me what it is if you can. Thanks!
java.lang.RuntimeException: Unable to start activity ComponentInfo{genius.mohammad.accelerometer.mouse/genius.mohammad.accelerometermouse.MainActivity}: java.lang.NumberFormatException: unable to parse 'MArcos' as integer
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NumberFormatException: unable to parse 'MArcos' as integer
at java.lang.Integer.parse(Integer.java:383)
at java.lang.Integer.parseInt(Integer.java:372)
at java.lang.Integer.parseInt(Integer.java:332)
at genius.mohammad.accelerometermouse.MainActivity.updatePrefs(MainActivity.java:85)
at genius.mohammad.accelerometermouse.MainActivity.onCreate(MainActivity.java:51)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
Caused by: java.lang.NumberFormatException: unable to parse 'MArcos' as integer
It seems in your code (MainActivity.java: line number 85) you are trying to parse String as Integer.

NullPointerException caused by setOnClickListener?

I'm getting overly frustrated with this issue. First of all, this did work fine with no issues, I have no idea why I'm now getting this error.
The application runs fine on my phone (v2.3.4) but not on one emulator (1.6 > 2.3)
The error I'm getting is 'NullPointerException' immediately after I load the application. Heres the DDMS
08-24 21:10:11.706: WARN/dalvikvm(423): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): FATAL EXCEPTION: main
08-24 21:10:11.726: ERROR/AndroidRuntime(423): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.app/com.myapp.app.SplashActivity}: java.lang.NullPointerException
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.os.Looper.loop(Looper.java:123)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.app.ActivityThread.main(ActivityThread.java:3647)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at java.lang.reflect.Method.invokeNative(Native Method)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at java.lang.reflect.Method.invoke(Method.java:507)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at dalvik.system.NativeStart.main(Native Method)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): Caused by: java.lang.NullPointerException
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at com.myapp.app.SplashActivity.onCreate(SplashActivity.java:43)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): ... 11 more
OK, so I look up what caused the problem (08-24 21:10:11.726: ERROR/AndroidRuntime(423): at com.myapp.app.SplashActivity.onCreate(SplashActivity.java:43))
Here is my onCreate:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
Button playBtn = (Button) findViewById(R.id.playBtn);
playBtn.setOnClickListener(this);
Button settingsBtn = (Button) findViewById(R.id.settingsBtn);
settingsBtn.setOnClickListener(this);
Button rulesBtn = (Button) findViewById(R.id.rulesBtn);
rulesBtn.setOnClickListener(this);
Button exitBtn = (Button) findViewById(R.id.exitBtn);
exitBtn.setOnClickListener(this);
}
Line 43 is the last one: exitBtn.setOnClickListener(this);
This is handled later on in the app using a switch statement for each button, the only code for the exit button is 'finish();' but it crashes 'onCreate' not onClick.
This is making no sense to me, this used to work fine and I haven't changed the code relating to this since it previously worked. Also, the exit button is set up exactly the same as all the other buttons (in src and layout files), so why would it crash when it gets to the exit button? As I said, this works OK on my cyn7 device but not on any of the emulators (it did)
This app has taken a massive amount of work to get it to this point, I was just doing final tests when this began.. so infuriating!
Can anyone please offer any suggestions to fix or even as to why this may happen?
EDIT: OK, this is really strange. I commented out the Exit button. Now my 'Play' button does nothing (even in DDMS it shows up nothing) the settings up OK and the Rules crashes, with the same error for the Rules activity on a setOnClickListener(this). Which makes no sense as the settings activity also has a 'setOnClickListener'. What is going on?!
Sounds like a corrupt worksapce. Android in Eclipse sometimes gets the autogenerated resource files out of sysnc with the actual layout. As Xion mentioned, a clean and rebuild will fix this via Project -> Clean... -> Clean all projects. Before doing this, ensure that Project -> Build Automatically is ticked.

NullPointerException in com.reg.project

I have no Idea why I get this error :/
Exception class java.lang.NullPointerException
Source method Jax$7.onClick()
java.lang.NullPointerException
at com.reg.lolsoundboard.Jax$7.onClick(Jax.java:83)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9089)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3806)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Obviously you are dereferencing a variable in line 83 of the file Jax.java where the variable is null.
java.lang.NullPointerException
at com.reg.lolsoundboard.Jax$7.onClick(Jax.java:83)
If show the relevant code, people may be able to help you.

assetmanager has been finalized?

I'm getting that exception when I pick a wallpaper. I'm actually not sure what function is the culprit. Here's the error log:
I/ActivityManager( 1360): Starting activity: Intent { cmp=com.android.wallpaper.livepicker/.LiveWallpaperPreview (has extras) }
W/dalvikvm(29175): threadid=1: thread exiting with uncaught exception (group=0x40020ac0)
E/AndroidRuntime(29175): FATAL EXCEPTION: main
E/AndroidRuntime(29175): java.lang.IllegalStateException: AssetManager has been finalized!
E/AndroidRuntime(29175): at android.content.res.AssetManager.isUpToDate(Native Method)
E/AndroidRuntime(29175): at android.app.ActivityThread.getPackageInfo(ActivityThread.java:2350)
E/AndroidRuntime(29175): at android.app.ActivityThread.getPackageInfoNoCheck(ActivityThread.java:2337)
E/AndroidRuntime(29175): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2935)
E/AndroidRuntime(29175): at android.app.ActivityThread.access$3300(ActivityThread.java:125)
E/AndroidRuntime(29175): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2087)
E/AndroidRuntime(29175): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(29175): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(29175): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(29175): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(29175): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(29175): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
E/AndroidRuntime(29175): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
E/AndroidRuntime(29175): at dalvik.system.NativeStart.main(Native Method)
I/ActivityManager( 1360): Displayed activity com.android.wallpaper.livepicker/.LiveWallpaperPreview: 331 ms (total 331 ms)
W/InputManagerService( 1360): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#44bf5a08
I/ActivityManager( 1360): Process com.bukabros.videolivewallpaper (pid 29175) has died.
W/ActivityManager( 1360): Scheduling restart of crashed service com.bukabros.videolivewallpaper/.VideoLiveWallpaper in 5000ms
I/ActivityManager( 1360): Start proc com.bukabros.videolivewallpaper for service com.bukabros.videolivewallpaper/.VideoLiveWallpaper: pid=29207 uid=10090 gids={}
The only thing I can think of is that onCreate doesn't get called in the right order when the wallpaper gets picked cuz that's where I instantiate the asset manager.
And yes, I'm using the NDK but the asset manager doesn't get used there.
Ah nevermind. The culprit was that the handle to the assetmanager was a static variable. (That was just a quick hack for something else). Making that a normal variable solved the problem.

Categories

Resources