java.lang.RuntimeException: Unable to instantiate activity error - java

I'm having an (with some devices) error caused by NullPointerException error with this code :
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
it's forces the screen orientation to portrait, is it well coded? because the error reports comes from a few android 4.4 devices.
UPDATES
As Mr. Gabe said, i guess line 35 is about here if imports line are hidden [+] :
Thread t = new Thread() {
public void run() {
try {
Thread.sleep(3000);
Intent i = new Intent(Splash.this, main.class);
startActivity(i);
finish();
here ------>
} catch (Exception e) {
e.printStackTrace();
}
This code is from splash activity, it's goes to main activity after 3 sec, i think everything here looks fine to me, what's can cause an NPE here?
UPDATE
the error report from the google play is :
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{aladin888.dessin/aladin888.dessin.Splash}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2208)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2340)
at android.app.ActivityThread.access$800(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.Activity.setRequestedOrientation(Activity.java:4453)
at aladin888.dessin.Splash.<init>(Splash.java:35)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
PS:How to make the lines numbers show up in eclipse?

Yes its fine and should work easily
Here is what i am using and is working fine too
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Although your codeline is fine, this error could have been cause due to invalid usage of 'this' key word.
Try using the xml alternative. Go to androidmanifest.xml and write
<
activity
android:name=".MyActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >

Related

DialogFragment is relaunching itself when startActivity on new Intent is called

In my Android application I have a dialog fragment that contains a ListView. The onclick handler of the items in the list view calls my internalPlayer method which calls a VideoView activity to play a video. The VideoView activity is used in other places within the app so I know it is working.
private void internalPlayer(final String channelUrl)
{
final Intent localIntent = new Intent(getActivity(), InternalVideoActivity.class);
localIntent.putExtra(EXTRA_VIDEO_URI, Uri.encode(channelUrl, ALLOWED_URI_CHARS).toString());
localIntent.putExtra(GridViewFragment.CHANNEL_NAME, mCategory.toString() + " Episode ");
getActivity().startActivity(localIntent);
}
When running the app in a tablet everything works well and the video activity starts and plays the video. When I run the app on a phone device when I click an item in the ListView the dialog fragment relaunches itself and because the serialized objects originally passed to it no longer exist there is a NullPointerException throw.
Here's the log:
04-16 19:34:33.790 6000-6000/com.xystra W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41998700)
04-16 19:34:33.790 6000-6000/com.xystra E/MAIN PHONE ACTIVITY: 1﹕ Unable to start activity ComponentInfo{com.xystra/com.xystra.activity.CatchUpSynopsisActivity}: java.lang.NullPointerException
04-16 19:34:33.814 6000-6000/com.xystra E/MAIN PHONE ACTIVITY﹕ STACK TRACE
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xystra/com.xystra.activity.CatchUpSynopsisActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3740)
at android.app.ActivityThread.access$700(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.xystra.ui.fragment.ProgramFragment.onCreateView(ProgramFragment.java:369)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1108)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1917)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:544)
at roboguice.activity.RoboFragmentActivity.onStart(RoboFragmentActivity.java:60)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
at android.app.Activity.performStart(Activity.java:5143)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3740)
            at android.app.ActivityThread.access$700(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
Any help or ideas are greatly appreciated.
More Info
The dialog fragment loads properly. The listview is populated everything is good.
When I click an item in the listview my internalPlayer method is called. When getActivity().startActivity(localIntent) is executed the dialog fragment relaunches itself instead of launching the new intent/activity.
Because the fragment is relaunching itself, the serialized objects that were originally passed the first time are not available or null so the dialog fragment returns the exception you see above.
Everything works perfectly on a tablet. Only on phone devices do I get this event.
Well I got rid of the dialog fragment and used the existing activity fragment for my view, ran some tests and was able to deduce that I had an arithmetic exception in an underlying activity for some reason that was causing the issue. Really don't know how that method got recalled to cause the exception. Thanks for all your help to those who commented.

Force close when app restarts

I really don't know how to start this, but I have searched through the whole of Google and stackoverflow.
I have this radio app which plays radio(duh) and display information about the song playing currently. But I have a problem here:
I have an Activity(MainActivity) and 3 Fragments(playerFragment, the rest are not important) and the fragments are tabs.
I parse the JSON data on MainActivity and display it on playerFragment. I am able to display it straight, no problems. But when I press the back the button and open the app again, it crashes immediately. Of course, I have a service playing the audio only and I ensure that the app loads the data when the user returns to the app(in this case the Activity and fragment is destroyed while service is still running). I checked the log it stated NullPointerException on the point when it starts to setText onCreate. I use the exact same code as it was to load the data at first (before destroying the Activity and Fragment).
I don't know how am I gonna post the code here because I do not know where went wrong and the code was long, please tell me which part of the code you would want to see to check what's wrong.
Code where it start to have error:
TextView titleTextView = (TextView) findViewById(R.id.titleTextView);
TextView artistTextView = (TextView) findViewById(R.id.artistTextView);
TextView lyricsTextView = (TextView) findViewById(R.id.lyricsTextView);
ImageView albumImageView = (ImageView) findViewById(R.id.albumImageView);
JSONObject jsonObject = new JSONObject(jsonData);
String title = jsonObject.getString("title");
String artist = jsonObject.getString("artist");
String lyrics = jsonObject.getString("lyrics");
String albumURL = jsonObject.getString("coverUrl");
STARTING HERE: ---> titleTextView.setText(title);
artistTextView.setText("\n" + artist);
lyricsTextView.setText("\n" + lyrics);
This code was able to display the data when I first open the app and parse it, the app the force close when I return/start to the app(while service is running).
The logcat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.brandon.sgpradio/com.brandon.sgpradio.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
at android.app.ActivityThread.access$900(ActivityThread.java:173)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.brandon.sgpradio.MainActivity.parseJson(MainActivity.java:225)
at com.brandon.sgpradio.MainActivity.isMyServiceRunning(MainActivity.java:282)
at com.brandon.sgpradio.MainActivity.onCreate(MainActivity.java:97)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
at android.app.ActivityThread.access$900(ActivityThread.java:173)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Thanks!
Update:
1. Add a tag to your fragment when you add it to the activity via ViewPager.
fragment = new playerFragment();
fragment.setTag("player_fragment");
Get the fragment via getFragmentManger().findFragmentByTag() method.
PlayerFragment pFragment =
getFragmentManager().findFragmentByTag("player_fragment");
if(pFragment != null)
{
pFragment.setTextViewText();
}

Can't locate error origin

I get this weird error in my MainActivity, can't reproduce it myself but this is what I get in Crash report:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65538, result=0, data=null} to activity {lv.mobi.android/lv.mobi.android.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3455)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3498)
at android.app.ActivityThread.access$1300(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5135)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at lv.mobi.android.b.aj.a(Unknown Source)
at android.support.v4.app.FragmentActivity.onActivityResult(Unknown Source)
at lv.mobi.android.MainActivity.onActivityResult(Unknown Source)
at android.app.Activity.dispatchActivityResult(Activity.java:5423)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3451)
... 11 more
I thought it could be something in onActivityResult, but can't figure out what, my result function doesn't have much in it:
#Override
protected void onActivityResult(int _requestCode, int _resultCode, Intent _data) {
super.onActivityResult(_requestCode, _resultCode, _data);
if(_resultCode==Activity.RESULT_OK){
reloadUser();
}
}
According to my guess, you need to put below code
if(resultCode != RESULT_CANCELED){
if(_resultCode==Activity.RESULT_OK){
reloadUser();
}
}
Because you are cancelling that activity/process due to that intent is getting null value.
For what i can see and based on the comments. It's a NullPointerException, witch means some where in your code you are not initializing a variable / class or something is returning null. If you like to read up on it to get a better understanding here is a link NullPointerException Documentation, also it would help to post some of your code.

java.lang.UnsatisfiedLinkError: Couldn't load eposprint: findLibrary returned null

I am using Android Studio. I am using e-POS-Print.jar in my app. Whenever I run the code I get this error:
java.lang.ExceptionInInitializerError
at com.stc.printer.MyActivity.onCreate(MyActivity.java:48)
at android.app.Activity.performCreate(Activity.java:5163)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load eposprint: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at com.epson.eposprint.Print.<clinit>(Print.java:18)
at com.stc.printer.MyActivity.onCreate(MyActivity.java:48)
My code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
System.out.println("started");
printerName = getString(R.string.printername_t81ii);
language = Builder.MODEL_SOUTHASIA;
//bellow is line no. 48
Print newPrinter = new Print(getApplicationContext());
try{
newPrinter.openPrinter(deviceType, openDeviceName, enabled, interval);
}catch(Exception e){
System.out.println("Error");
e.printStackTrace();
newPrinter = null;
}
setPrinter(newPrinter);
}
The sample project from Epson is having one native file with .so extension. But even if I remove that file from sample project it works.
I also tried adding that file to my project. But I am not able to add that file to my build path.
I also referred multiple answers from this link but I am unsuccessful.
After checking many sites, reading multiple answers, finally I figured out the solution.
Create folder tree as:
|---src
|---main
|---jniLibs
|---armeabi
|---nativeLib.so
Place your files under armeabi folder. And it will work.
More about java.lang.unsatisfiedlinkerror

Trying to add a Facebook Friend Picker, but get null pointer exception

I'm trying to learn and add some basic Facebook functionality to my Android App (an address book). What I'm eventually going to do is import a friends profile picture. I've currently only copy/pasted what I need from the "FriendPickerSample" example project, which is just a button that brings up a friend picker fragment, and, if I remember correctly, it places the names you picked into a list. I've altered it to come up when an imageview is clicked, and it'll just Toast the single name that is chosen. When I try to bring up the friend picker, I get a null pointer exception, and I don't understand why. Here's the log:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.JDE.RAB/com.JDE.RAB.PickFriendsActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.facebook.widget.PickerFragment.onCreateView(PickerFragment.java:152)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:871)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:635)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:523)
at com.JDE.RAB.PickFriendsActivity.onStart(PickFriendsActivity.java:112)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
at android.app.Activity.performStart(Activity.java:3781)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636)
... 11 more
This is the code in my onclick, which is supposed to open the PickFriendsActivity:
if (Session.getActiveSession() == null || Session.getActiveSession().isClosed())
{
Session.openActiveSession(AddNewTabLayoutActivity.this, true, null);
}//endif
FriendPickerApplication application = (FriendPickerApplication) GetMyApplication();
application.setSelectedUsers(null);
Intent intent = new Intent(AddNewTabLayoutActivity.this, PickFriendsActivity.class);
// Note: The following line is optional, as multi-select behavior is the default for
// FriendPickerFragment. It is here to demonstrate how parameters could be passed to the
// friend picker if single-select functionality was desired, or if a different user ID was
// desired (for instance, to see friends of a friend).
//multi-select is OFF
PickFriendsActivity.populateParameters(intent, null, false, true);
Debugger.SendNotification(getApplicationContext(), "Alert", "Alert", "Starting Activity For Result", 3009);
startActivityForResult(intent, 2);
PickFriendsActivity, line 112 is super.onStart(); Should I post the entirety of that activities source code?
Thanks for any help!
You should copy res/layout/pick_friends_activity.xml to your own project too.

Categories

Resources