Force close in android app landscape mode - Null pointer exception - android

My app works good in portrait mode. when i use landscape mode and perform any activity it gets force close. The log says null pointer exception. I verified with the source all the information is passing good but getting force close.
Log:
10-24 17:14:38.566: E/AndroidRuntime(3684): FATAL EXCEPTION: main
10-24 17:14:38.566: E/AndroidRuntime(3684): java.lang.RuntimeException: Unable to start activity ComponentInfo{/app.UserPage}: java.lang.NullPointerException
10-24 17:14:38.566: E/AndroidRuntime(3684): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
10-24 17:14:38.566: E/AndroidRuntime(3684): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
10-24 17:14:38.566: E/AndroidRuntime(3684): at android.app.ActivityThread.access$600(ActivityThread.java:162)
10-24 17:14:38.566: E/AndroidRuntime(3684): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
10-24 17:14:38.566: E/AndroidRuntime(3684): at android.os.Handler.dispatchMessage(Handler.java:107)
10-24 17:14:38.566: E/AndroidRuntime(3684): at android.os.Looper.loop(Looper.java:194)
10-24 17:14:38.566: E/AndroidRuntime(3684): at android.app.ActivityThread.main(ActivityThread.java:5371)
10-24 17:14:38.566: E/AndroidRuntime(3684): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 17:14:38.566: E/AndroidRuntime(3684): at java.lang.reflect.Method.invoke(Method.java:525)
10-24 17:14:38.566: E/AndroidRuntime(3684): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
10-24 17:14:38.566: E/AndroidRuntime(3684): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
10-24 17:14:38.566: E/AndroidRuntime(3684): at dalvik.system.NativeStart.main(Native Method)
10-24 17:14:38.566: E/AndroidRuntime(3684): Caused by: java.lang.NullPointerException
10-24 17:14:38.566: E/AndroidRuntime(3684): at app.UserPage.onCreate(UserPage.java:219)
10-24 17:14:38.566: E/AndroidRuntime(3684): at android.app.Activity.performCreate(Activity.java:5122)
10-24 17:14:38.566: E/AndroidRuntime(3684): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
10-24 17:14:38.566: E/AndroidRuntime(3684): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
10-24 17:14:38.566: E/AndroidRuntime(3684): ... 11 more

Related

resuming activity nullpointer exception

I have an activity that has a view pager and loads it's images from a JSON ( and so, several fragments ).
When I do some kind of external activity like start a phonecall or see a website ( via my aplication ), when this activity resumes it gives me a null pointer exception.
10-24 19:36:56.626: E/AndroidRuntime(18567): FATAL EXCEPTION: main
10-24 19:36:56.626: E/AndroidRuntime(18567): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.imagefromurl/com.example.imagefromurl.MainActivity}: java.lang.NullPointerException
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2373)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2425)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.app.ActivityThread.access$600(ActivityThread.java:162)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.os.Handler.dispatchMessage(Handler.java:107)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.os.Looper.loop(Looper.java:194)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.app.ActivityThread.main(ActivityThread.java:5422)
10-24 19:36:56.626: E/AndroidRuntime(18567): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 19:36:56.626: E/AndroidRuntime(18567): at java.lang.reflect.Method.invoke(Method.java:525)
10-24 19:36:56.626: E/AndroidRuntime(18567): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:837)
10-24 19:36:56.626: E/AndroidRuntime(18567): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
10-24 19:36:56.626: E/AndroidRuntime(18567): at dalvik.system.NativeStart.main(Native Method)
10-24 19:36:56.626: E/AndroidRuntime(18567): Caused by: java.lang.NullPointerException
10-24 19:36:56.626: E/AndroidRuntime(18567): at com.example.imagefromurl.FragmentOne.onCreateView(FragmentOne.java:28)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1103)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1901)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:567)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1167)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.app.Activity.performStart(Activity.java:5132)
10-24 19:36:56.626: E/AndroidRuntime(18567): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2346)
10-24 19:36:56.626: E/AndroidRuntime(18567): ... 11 more
Is the any way that I can solve this?
Line 28: sUrl = activity.urlProfile.toString();
translation - on main activity I run the AsynkTask and I get this string sUrl . then on the fragment I cast the activity and get the string ( probably you would figure that by yourselves but it doesnt hurt to describe it all )
Either the fragment has lost the instance of that activity, so the field activity is null.
Or the the field inside the activity urlProfile is null.
Or you casted your activity into a wrong activity, usually you get the activity with getActivity() or you catch that from the parameters.
But the main problem is, that you try to call toString() on a null which causes the exception. Try to catch it with
if(activity != null && activity.urlProfile != null) {
sUrl = activity.urlProfile.toString();
} else {
// do something different when those objects are null
}

Android Facebook ApiException: Invalid Application

I am getting Facebook ApiException: Invalid Application error when I try to log in with some other account apart from my Developer Account and even my sandbox mode is off as I have checked with other posts having same issue.Thanks in advance.
10-24 17:03:24.355: W/System.err(13721): com.facebook.FacebookAuthorizationException: UnknownError: ApiException:Invalid application 165081033652784
10-24 17:03:24.355: W/System.err(13721): at com.facebook.Session.handleAuthorizationResult(Session.java:1078)
10-24 17:03:24.355: W/System.err(13721): at com.facebook.Session.onActivityResult(Session.java:554)
10-24 17:03:24.355: W/System.err(13721): at com.facebook.UiLifecycleHelper.onActivityResult(UiLifecycleHelper.java:144)
10-24 17:03:24.355: W/System.err(13721): at com.punchh.base.FacebookActivity.onActivityResult(FacebookActivity.java:141)
10-24 17:03:24.355: W/System.err(13721): at android.app.Activity.dispatchActivityResult(Activity.java:5390)
10-24 17:03:24.355: W/System.err(13721): at android.app.ActivityThread.deliverResults(ActivityThread.java:3201)
10-24 17:03:24.355: W/System.err(13721): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3248)
10-24 17:03:24.355: W/System.err(13721): at android.app.ActivityThread.access$1200(ActivityThread.java:140)
10-24 17:03:24.355: W/System.err(13721): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1285)
10-24 17:03:24.355: W/System.err(13721): at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 17:03:24.355: W/System.err(13721): at android.os.Looper.loop(Looper.java:137)
10-24 17:03:24.355: W/System.err(13721): at android.app.ActivityThread.main(ActivityThread.java:4935)
10-24 17:03:24.355: W/System.err(13721): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 17:03:24.355: W/System.err(13721): at java.lang.reflect.Method.invoke(Method.java:511)
10-24 17:03:24.355: W/System.err(13721): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
10-24 17:03:24.355: W/System.err(13721): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
10-24 17:03:24.355: W/System.err(13721): at dalvik.system.NativeStart.main(Native Method)
I had the same problems, check the facebook's application configuration, maybe is on Developer Mode (SandBox). Only developer users added in developer roles can see the app and use it.
Try changing the app configuration to public app.
Take a note: If you set like "Public App" all facebook user will be able to see your app. If your application is in development period it's better work with Facebook Roles. When your app is in release period it is time to change to "Public App"

Android: runtime-error 'Unable to create directory', on use of class DownloadManager, method setDestinationInExternalPublicDir

I'm getting this exception:
10-24 17:08:19.711: E/AndroidRuntime(1379): FATAL EXCEPTION: main
10-24 17:08:19.711: E/AndroidRuntime(1379): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.campusfqm.cfqm/br.com.campusfqm.cfqm.DownloadManagerActivity}: java.lang.IllegalStateException: Unable to create directory: /mnt/sdcard/Download
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.os.Looper.loop(Looper.java:126)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.ActivityThread.main(ActivityThread.java:3997)
10-24 17:08:19.711: E/AndroidRuntime(1379): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 17:08:19.711: E/AndroidRuntime(1379): at java.lang.reflect.Method.invoke(Method.java:491)
10-24 17:08:19.711: E/AndroidRuntime(1379): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
10-24 17:08:19.711: E/AndroidRuntime(1379): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
10-24 17:08:19.711: E/AndroidRuntime(1379): at dalvik.system.NativeStart.main(Native Method)
10-24 17:08:19.711: E/AndroidRuntime(1379): Caused by: java.lang.IllegalStateException: Unable to create directory: /mnt/sdcard/Download
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.DownloadManager$Request.setDestinationInExternalPublicDir(DownloadManager.java:466)
10-24 17:08:19.711: E/AndroidRuntime(1379): at br.com.campusfqm.cfqm.DownloadManagerActivity.download(DownloadManagerActivity.java:51)
10-24 17:08:19.711: E/AndroidRuntime(1379): at br.com.campusfqm.cfqm.DownloadManagerActivity.onCreate(DownloadManagerActivity.java:43)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
10-24 17:08:19.711: E/AndroidRuntime(1379): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
10-24 17:08:19.711: E/AndroidRuntime(1379): ... 11 more
Using the class DownloadManager, with this code:
DownloadManager.Request request = new DownloadManager.Request(Uri.parse("http://centraldemangas.com.br/forum/dbtech/vbshop/images/gifts/pidgey.gif"));
request.setAllowedNetworkTypes(Request.NETWORK_MOBILE | Request.NETWORK_WIFI);
request.setAllowedOverRoaming(false);
request.setTitle("pidgey.gif");
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"pid.gif");
id = downloadManager.enqueue(request);
The exception is pointing to request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"pid.gif");
The problem is in
Unable to create directory: /mnt/sdcard/Download
Try this:
String name = Environment.getExternalStorageDirectory().getAbsolutePath();
name += "/YourDirectoryName/" ;
Do you have the proper permissions in your Manifest ?
See WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions
I think you didn't give a sd card size when you crated the emulator.

how to launch android application Manager

Does anyone know the package name for Application Manager on android. I have a method that i want to allow the user to go directly from my app to the application manager:
public void goToApplicationManager(){
Intent startMain = this.getPackageManager().getLaunchIntentForPackage("com.android.settings.ManageApplications");
startActivity(startMain);
}
but that throws an error.. i can just do com.android.settings, and it will take the user to settings but i would like to take them specifically to the application manager. do i have the wrong package name?
my error:
10-24 13:36:43.748: E/AndroidRuntime(31133): FATAL EXCEPTION: main
10-24 13:36:43.748: E/AndroidRuntime(31133): java.lang.NullPointerException
10-24 13:36:43.748: E/AndroidRuntime(31133): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1382)
10-24 13:36:43.748: E/AndroidRuntime(31133): at android.app.Activity.startActivityForResult(Activity.java:3190)
10-24 13:36:43.748: E/AndroidRuntime(31133): at android.app.Activity.startActivity(Activity.java:3297)
10-24 13:36:43.748: E/AndroidRuntime(31133): at com.eliddell.services_test.ServiceLauncher.goToApplicationManager(ServiceLauncher.java:101)
10-24 13:36:43.748: E/AndroidRuntime(31133): at com.eliddell.services_test.ServiceLauncher$4.onClick(ServiceLauncher.java:156)
10-24 13:36:43.748: E/AndroidRuntime(31133): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:168)
10-24 13:36:43.748: E/AndroidRuntime(31133): at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 13:36:43.748: E/AndroidRuntime(31133): at android.os.Looper.loop(Looper.java:137)
10-24 13:36:43.748: E/AndroidRuntime(31133): at android.app.ActivityThread.main(ActivityThread.java:4514)
10-24 13:36:43.748: E/AndroidRuntime(31133): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 13:36:43.748: E/AndroidRuntime(31133): at java.lang.reflect.Method.invoke(Method.java:511)
10-24 13:36:43.748: E/AndroidRuntime(31133): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
10-24 13:36:43.748: E/AndroidRuntime(31133): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
10-24 13:36:43.748: E/AndroidRuntime(31133): at dalvik.system.NativeStart.main(Native Method)
startActivity(
new Intent(android.provider.Settings.ACTION_APPLICATION_SETTINGS), 0);
Have you looked at ACTION_MANAGE_APPLICATIONS_SETTINGS or ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS?

Android: Recource$NotFoundException

Im working with android, and am releatively new to it, Ive got an exception I cant seem to fix.
Logcat output
10-24 13:50:59.941: E/AndroidRuntime(772): FATAL EXCEPTION: main
10-24 13:50:59.941: E/AndroidRuntime(772): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.metronome/com.metronome.MainActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x78
10-24 13:50:59.941: E/AndroidRuntime(772): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
10-24 13:50:59.941: E/AndroidRuntime(772): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
10-24 13:50:59.941: E/AndroidRuntime(772): at android.app.ActivityThread.access$600(ActivityThread.java:122)
10-24 13:50:59.941: E/AndroidRuntime(772): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
10-24 13:50:59.941: E/AndroidRuntime(772): at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 13:50:59.941: E/AndroidRuntime(772): at android.os.Looper.loop(Looper.java:137)
10-24 13:50:59.941: E/AndroidRuntime(772): at android.app.ActivityThread.main(ActivityThread.java:4340)
10-24 13:50:59.941: E/AndroidRuntime(772): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 13:50:59.941: E/AndroidRuntime(772): at java.lang.reflect.Method.invoke(Method.java:511)
10-24 13:50:59.941: E/AndroidRuntime(772): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-24 13:50:59.941: E/AndroidRuntime(772): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-24 13:50:59.941: E/AndroidRuntime(772): at dalvik.system.NativeStart.main(Native Method)
10-24 13:50:59.941: E/AndroidRuntime(772): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x78
10-24 13:50:59.941: E/AndroidRuntime(772): at android.content.res.Resources.getText(Resources.java:247)
10-24 13:50:59.941: E/AndroidRuntime(772): at android.widget.TextView.setText(TextView.java:3432)
10-24 13:50:59.941: E/AndroidRuntime(772): at com.metronome.MainActivity.onCreate(MainActivity.java:36)
10-24 13:50:59.941: E/AndroidRuntime(772): at android.app.Activity.performCreate(Activity.java:4465)
10-24 13:50:59.941: E/AndroidRuntime(772): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-24 13:50:59.941: E/AndroidRuntime(772): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
10-24 13:50:59.941: E/AndroidRuntime(772): ... 11 more
Ive read that people say to fix the problem by cleaning the project but I have tried that twice and it didnt help. I also creted another project and copied the code, so I think it is something different. Any help is appreciated.
Line 36
txtBPM1.setText(120, TextView.BufferType.EDITABLE);
This error occurs when you access some controls or which is not present in your layout you pass on onCreate in you activity setContentView(R.layout.your_layout);. Just checkout all the id's , string's and other controls which you are using belongs to same layout or not
change 120 to be a string like so :
txtBPM1.setText(""+120, TextView.BufferType.EDITABLE);
(your error in MainActivity.java:line 36 (it is import generated R))
1.delete error line from import and use pop-up message on red R.id.**
2. close and reopen IDE

Categories

Resources