Screen Rotation unable to start activity Null pointer exception - android

When I run my app in landscape mode it has no issues nor does it have any issues in portrait mode until i try to add an item to one of my lists while still in portrait mode, where of which my app crashes.
any ideas on how to fix this??
here is the error I am getting as feedback in logcat....
03-08 13:30:50.201: D/AndroidRuntime(554): Shutting down VM
03-08 13:30:50.201: W/dalvikvm(554): threadid=1: thread exiting with uncaught exception (group=0x40014760)
03-08 13:30:50.229: E/AndroidRuntime(554): FATAL EXCEPTION: main
03-08 13:30:50.229: E/AndroidRuntime(554): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ATG.C3FactSystemTabbed/com.ATG.EditActivities.AmenitiesEditActivity}: java.lang.NullPointerException
03-08 13:30:50.229: E/AndroidRuntime(554): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1748)
03-08 13:30:50.229: E/AndroidRuntime(554): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
03-08 13:30:50.229: E/AndroidRuntime(554): at android.app.ActivityThread.access$1500(ActivityThread.java:122)
03-08 13:30:50.229: E/AndroidRuntime(554): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
03-08 13:30:50.229: E/AndroidRuntime(554): at android.os.Handler.dispatchMessage(Handler.java:99)
03-08 13:30:50.229: E/AndroidRuntime(554): at android.os.Looper.loop(Looper.java:132)
03-08 13:30:50.229: E/AndroidRuntime(554): at android.app.ActivityThread.main(ActivityThread.java:4025)
03-08 13:30:50.229: E/AndroidRuntime(554): at java.lang.reflect.Method.invokeNative(Native Method)
03-08 13:30:50.229: E/AndroidRuntime(554): at java.lang.reflect.Method.invoke(Method.java:491)
03-08 13:30:50.229: E/AndroidRuntime(554): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
03-08 13:30:50.229: E/AndroidRuntime(554): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
03-08 13:30:50.229: E/AndroidRuntime(554): at dalvik.system.NativeStart.main(Native Method)
03-08 13:30:50.229: E/AndroidRuntime(554): Caused by: java.lang.NullPointerException
03-08 13:30:50.229: E/AndroidRuntime(554): at com.ATG.EditActivities.AmenitiesEditActivity.registerButtonListenersAndSetDefaultText(AmenitiesEditActivity.java:68)
03-08 13:30:50.229: E/AndroidRuntime(554): at com.ATG.EditActivities.AmenitiesEditActivity.onCreate(AmenitiesEditActivity.java:61)
03-08 13:30:50.229: E/AndroidRuntime(554): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
03-08 13:30:50.229: E/AndroidRuntime(554): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712)
03-08 13:30:50.229: E/AndroidRuntime(554): ... 11 more
this is the line that throws the exception
btnSave.setOnClickListener(new View.OnClickListener(){ <-------
#Override
public void onClick(View v){
. . . . .
}
});
this is only thrown when I am in portrait mode, it never gets thrown unless i change the orientation before trying to add something to the list. And if i already have the view open to add something no matter how i change the orientation it won't force close.
okay so i checked the files again i had different names for the buttons i was referencing in different xml files. In other words in landscape i was calling the button btnSave and in the other i was calling it btnAmenitiesSave. Problem solved thanks everyone!!!!!!

btnSave is set to null in portrait.
It means :
btnSave is not assigned ( no btnSave = findViewById(....) )
or the id the_id specified in btnSave = findViewById(R.id.the_id) does not exist in the portait layout

Related

ClassNotFoundException despite class seemingly still there

I have an app in which I have
public class mainactivity extends Activity implements View.OnClickListener
{
...
and I declare it in that manifest. Everything compiles and runs perfectly. Then I change the class as follows:
public class mainactivity extends Activity implements View.OnClickListener , MoPubInterstitialListener
{
...
+ extra code to do with "mopub"
this new code compiles, but now, as soon as my splash screen activity shuts down and hands over to mainactivity, I see
03-08 10:47:40.380: I/dalvikvm(9013): Failed resolving Lcom/mycompany/myapp/mainactivity; interface 1127 'Lcom/mopub/mobileads/MoPubInterstitial$MoPubInterstitialListener;'
03-08 10:47:40.380: W/dalvikvm(9013): Link of class 'Lcom/mycompany/myapp/mainactivity;' failed
03-08 10:47:40.380: D/AndroidRuntime(9013): Shutting down VM
03-08 10:47:40.380: W/dalvikvm(9013): threadid=1: thread exiting with uncaught exception (group=0x40c7e1f8)
03-08 10:47:40.385: E/AndroidRuntime(9013): FATAL EXCEPTION: main
03-08 10:47:40.385: E/AndroidRuntime(9013): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mycompany.myapp/com.mycompany.myapp.mainactivity}: java.lang.ClassNotFoundException: com.mycompany.myapp.mainactivity
03-08 10:47:40.385: E/AndroidRuntime(9013): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
03-08 10:47:40.385: E/AndroidRuntime(9013): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
03-08 10:47:40.385: E/AndroidRuntime(9013): at android.app.ActivityThread.access$600(ActivityThread.java:127)
03-08 10:47:40.385: E/AndroidRuntime(9013): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
03-08 10:47:40.385: E/AndroidRuntime(9013): at android.os.Handler.dispatchMessage(Handler.java:99)
03-08 10:47:40.385: E/AndroidRuntime(9013): at android.os.Looper.loop(Looper.java:137)
03-08 10:47:40.385: E/AndroidRuntime(9013): at android.app.ActivityThread.main(ActivityThread.java:4511)
03-08 10:47:40.385: E/AndroidRuntime(9013): at java.lang.reflect.Method.invokeNative(Native Method)
03-08 10:47:40.385: E/AndroidRuntime(9013): at java.lang.reflect.Method.invoke(Method.java:511)
03-08 10:47:40.385: E/AndroidRuntime(9013): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
03-08 10:47:40.385: E/AndroidRuntime(9013): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
03-08 10:47:40.385: E/AndroidRuntime(9013): at dalvik.system.NativeStart.main(Native Method)
03-08 10:47:40.385: E/AndroidRuntime(9013): Caused by: java.lang.ClassNotFoundException: com.mycompany.myapp.mainactivity
03-08 10:47:40.385: E/AndroidRuntime(9013): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
03-08 10:47:40.385: E/AndroidRuntime(9013): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-08 10:47:40.385: E/AndroidRuntime(9013): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-08 10:47:40.385: E/AndroidRuntime(9013): at android.app.Instrumentation.newActivity(Instrumentation.java:1026)
03-08 10:47:40.385: E/AndroidRuntime(9013): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
03-08 10:47:40.385: E/AndroidRuntime(9013): ... 11 more
I'm at a loss as to how to proceed. If I try the debugger it appears that not even the first line of mainactivity.OnCreate() is executed.
EDIT: I have the following included in my manifest:
<activity android:name="com.mopub.mobileads.MoPubActivity"
android:configChanges="keyboardHidden|orientation"/>
Classpath
If this ring a bell, then read on.
Diagnosis:
It means the compiler find these classes during compile-time but this class is not found in your classpath during runtime
Medicine:
I've had this before and am not perfectly sure of the steps but let me put you in the right direcction.
If you're using ADT and eclipse, check your .classpath in your project.
check the build order in project->build properties
check if your jar is included in the build path
isLibraryProject
If the ComponentInfo is part of a library project, then it's a CardinalSin (seriously!) to include it in your build path manually. You are supposed to just add is a library project in project properties->android tab.
Did you define the MoPub activity in your Manifest?
<activity android:name="com.mopub.mobileads.MoPubActivity"
android:configChanges="keyboardHidden|orientation"/>
Go have a look at this link. It should solve your problem.
I had a similar issue and I checked on the android-support-v4.jar checkbox under Java Build Path - Order and Export.

Exception while extend DroidGap

I done few phone gap projects before, This time a new exception raised in my code .
In my new project i include phonegap jar(cordova 1.5) and in the manifest i declared droidgap class(tried with both com.hb.DroidGap and org.apache.cordova.DroidGap).
now if i extend to Activity the debugger entering to onCreate method but if i extend to DroidGap
the below exception is coming and app geting force close (Debugger in not coming to onCreate) ...
Is there any thing i am missing ?
Thanks in advance and sorry for my poor English
06-07 10:03:54.954: E/AndroidRuntime(554): FATAL EXCEPTION: main
06-07 10:03:54.954: E/AndroidRuntime(554): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.hiddenbrains/com.hiddenbrains.HBPluginsActivity}: java.lang.ClassNotFoundException: com.hiddenbrains.HBPluginsActivity in loader dalvik.system.PathClassLoader[/data/app/com.hiddenbrains-1.apk]
06-07 10:03:54.954: E/AndroidRuntime(554): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
06-07 10:03:54.954: E/AndroidRuntime(554): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-07 10:03:54.954: E/AndroidRuntime(554): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-07 10:03:54.954: E/AndroidRuntime(554): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-07 10:03:54.954: E/AndroidRuntime(554): at android.os.Handler.dispatchMessage(Handler.java:99)
06-07 10:03:54.954: E/AndroidRuntime(554): at android.os.Looper.loop(Looper.java:123)
06-07 10:03:54.954: E/AndroidRuntime(554): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-07 10:03:54.954: E/AndroidRuntime(554): at java.lang.reflect.Method.invokeNative(Native Method)
06-07 10:03:54.954: E/AndroidRuntime(554): at java.lang.reflect.Method.invoke(Method.java:521)
06-07 10:03:54.954: E/AndroidRuntime(554): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-07 10:03:54.954: E/AndroidRuntime(554): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-07 10:03:54.954: E/AndroidRuntime(554): at dalvik.system.NativeStart.main(Native Method)
06-07 10:03:54.954: E/AndroidRuntime(554): Caused by: java.lang.ClassNotFoundException: com.hiddenbrains.HBPluginsActivity in loader dalvik.system.PathClassLoader[/data/app/com.hiddenbrains-1.apk]
06-07 10:03:54.954: E/AndroidRuntime(554): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
06-07 10:03:54.954: E/AndroidRuntime(554): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
06-07 10:03:54.954: E/AndroidRuntime(554): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
06-07 10:03:54.954: E/AndroidRuntime(554): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-07 10:03:54.954: E/AndroidRuntime(554): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
06-07 10:03:54.954: E/AndroidRuntime(554): ... 11 more
I have this exact problem too. Everything was working until a specific time last night, then I started getting these errors. App crashes every time. I have traced the problem to the .java file in src>MyApp.name... if I remove the cordova line, eg. class MyApp extends DroidGap and set it to the default the app doesn't crash, but it doesn't work either.

Unable to start activity android.view.InflateException

i have a created android project and within it i have created two package
--net.website.custom_listview
--main_activity_customview.java
--other files .....
--net.website.dashboard
--main_activity_dashboard.java
--other files .....
in my AndroidManifest.xml file
<activity
android:name="net.website.dashboard.main_activity_dashboard"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
so when i run the android app i am getting the following errors..
here is my logCat:
03-08 22:02:03.941: E/AndroidRuntime(691): FATAL EXCEPTION: main
03-08 22:02:03.941: E/AndroidRuntime(691): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.website/net.website.dashboard.Main_Activity_Dashboard}: android.view.InflateException: Binary XML file line #1: Error inflating class net.website.dashboard
03-08 22:02:03.941: E/AndroidRuntime(691): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.os.Handler.dispatchMessage(Handler.java:99)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.os.Looper.loop(Looper.java:123)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-08 22:02:03.941: E/AndroidRuntime(691): at java.lang.reflect.Method.invokeNative(Native Method)
03-08 22:02:03.941: E/AndroidRuntime(691): at java.lang.reflect.Method.invoke(Method.java:507)
03-08 22:02:03.941: E/AndroidRuntime(691): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-08 22:02:03.941: E/AndroidRuntime(691): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-08 22:02:03.941: E/AndroidRuntime(691): at dalvik.system.NativeStart.main(Native Method)
03-08 22:02:03.941: E/AndroidRuntime(691): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class net.website.dashboard
03-08 22:02:03.941: E/AndroidRuntime(691): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.view.LayoutInflater.parseInclude(LayoutInflater.java:684)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.view.LayoutInflater.rInflate(LayoutInflater.java:619)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-08 22:02:03.941: E/AndroidRuntime(691): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.app.Activity.setContentView(Activity.java:1657)
03-08 22:02:03.941: E/AndroidRuntime(691): at net.website.dashboard.Main_Activity_Dashboard.onCreate(Main_Activity_Dashboard.java:16)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-08 22:02:03.941: E/AndroidRuntime(691): ... 11 more
03-08 22:02:03.941: E/AndroidRuntime(691): Caused by: java.lang.ClassNotFoundException: net.website.dashboard in loader dalvik.system.PathClassLoader[/data/app/net.website-2.apk]
03-08 22:02:03.941: E/AndroidRuntime(691): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
03-08 22:02:03.941: E/AndroidRuntime(691): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
03-08 22:02:03.941: E/AndroidRuntime(691): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
03-08 22:02:03.941: E/AndroidRuntime(691): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
The problem is in your layout XML file. You're referencing the class "net.website.dashboard" but it doesn't exist.
You have to change the name for your packege and then after you have to check this.and also check your xml file

Why would onTouch() generate FATAL EXCEPTION when returning false?

I wrote a simple MotionEvent exercise in which all I do is log the parameters of the event. I do that by implementing OnTouchListener and overriding onTouch() in the main activity.
For one button, I return true at the end of onTouch(). No problems there.
For another button, I return false at the end of onTouch(). This is where it gets interesting. By mere returning 'false', a FATAL EXCEPTION is thrown with a tiny hint which I don't really understand: "recycled twice!".
What does this mean?
Update: per the suggestion in the comment below, I am adding the details of the exception from LogCat:
03-08 10:35:14.275: ERROR/AndroidRuntime(521): FATAL EXCEPTION: main
03-08 10:35:14.275: ERROR/AndroidRuntime(521): java.lang.RuntimeException: MotionEvent{405215b0 action=0 x=66.0 y=78.0 pressure=1.0 size=0.0} recycled twice!
03-08 10:35:14.275: ERROR/AndroidRuntime(521): at android.view.MotionEvent.recycle(MotionEvent.java:659)
03-08 10:35:14.275: ERROR/AndroidRuntime(521): at android.view.ViewRoot.handleMessage(ViewRoot.java:1880)
03-08 10:35:14.275: ERROR/AndroidRuntime(521): at android.os.Handler.dispatchMessage(Handler.java:99)
03-08 10:35:14.275: ERROR/AndroidRuntime(521): at android.os.Looper.loop(Looper.java:123)
03-08 10:35:14.275: ERROR/AndroidRuntime(521): at android.app.ActivityThread.main(ActivityThread.java:3647)
03-08 10:35:14.275: ERROR/AndroidRuntime(521): at java.lang.reflect.Method.invokeNative(Native Method)
03-08 10:35:14.275: ERROR/AndroidRuntime(521): at java.lang.reflect.Method.invoke(Method.java:507)
03-08 10:35:14.275: ERROR/AndroidRuntime(521): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-08 10:35:14.275: ERROR/AndroidRuntime(521): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-08 10:35:14.275: ERROR/AndroidRuntime(521): at dalvik.system.NativeStart.main(Native Method)
Are you recycling and then passing false?
The framework will assume that the MotionEvent is still valid if you return false and will do its own processing with it.
From the docs:
Recycle the MotionEvent, to be re-used
by a later caller. After calling this
function you must not ever touch the
event again.

Android Get Image Uri from Camera

I have an application that calls the android phone's default camera to take photo the following is my code.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE);
and in the onActivityResult method I am doing the following
if ((requestCode == TAKE_PICTURE) && (resultCode == Activity.RESULT_OK)) {
Uri photoPath = intent.getData();
// do something with the uri here
}
The above code works fine on htc Tatto and Sony ericsson's x10 running 1.6 but in on htc G1 running 1.6 the above code causes the following exception
03-08 18:54:25.906: ERROR/AndroidRuntime(4344): Uncaught handler: thread main exiting due to uncaught exception
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=inline-data (has extras) }} to activity removed
java.lang.NullPointerException
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.app.ActivityThread.deliverResults(ActivityThread.java:3224)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3266)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.app.ActivityThread.access$2600(ActivityThread.java:116)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1823)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.os.Handler.dispatchMessage(Handler.java:99)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.os.Looper.loop(Looper.java:123)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.app.ActivityThread.main(ActivityThread.java:4203)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at java.lang.reflect.Method.invokeNative(Native Method)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at java.lang.reflect.Method.invoke(Method.java:521)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at dalvik.system.NativeStart.main(Native Method)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): Caused by: java.lang.NullPointerException
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at removed
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.app.Activity.dispatchActivityResult(Activity.java:3624)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): at android.app.ActivityThread.deliverResults(ActivityThread.java:3220)
03-08 18:54:25.966: ERROR/AndroidRuntime(4344): ... 11 more
I have removed the app's package name from the exception
Any insights into how to solve this problem. Thank you.
onActivityResult:
Try to use: Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
It is probably related to this question and to this bug in android.

Categories

Resources