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

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.

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.

onclick Caused by: java.lang.NullPointerException

I'm new to Android development. I recently encoutered an issue when I hit a button on my application. I'm not sure what caused this because it worked flawlessly before I did some editing with the app, adding another activity, removing the software menu buttons on the splash screen, some other stuff. Not much of it had to do with the first activity which is where this problem exists. I would've posted all of the code but this website refused to let me do so
When I hit my button (readybutton) I get the following error:
java.lang.RuntimeException: Unable to start activity ComponentInfo
{com.unviewedchat/com.unviewedchat.SecondActivity}:
java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.unviewedchat.SecondActivity.onCreate(SecondActivity.java:23)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
 
    
      
Button code (readybutton)
button1 = (Button)findViewById(R.id.readybutton);
button1.setOnClickListener(this);
}
Button button1;
private void readyButtonclick()
{
startActivity(new Intent("unviewedchat.SecondActivity"));
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.readybutton:
readyButtonclick();
break;
}
}
SecondActivity row 22-23
button2 = (Button)findViewById(R.id.help);
button2.setOnClickListener(this); }
this code is for the software menu buttons to open the help screen, does this actually effect the button code for FirstActivity?
There is no code on SecondActivity that i'm trying to access, i'm trying to go to that activity when someone hits the button.
I attempted to post all of the error report, only to get told it wasn't formatted correctly when it was, either way I added almost all of it.
Just change:
startActivity(new Intent("unviewedchat.SecondActivity"));
with this:
startActivity(new Intent(this, SecondActivity.class));
Caused by: java.lang.NullPointerException
at com.unviewedchat.SecondActivity.onCreate(SecondActivity.java:23)
So in here:
SecondActivity row 22-23
button2 = (Button)findViewById(R.id.help);
button2.setOnClickListener(this); }
... button2 is null. Either your layout you've set with setContentView() does not contain a view with id help, or you haven't called setContentView() at all. In either case findViewById() returns null.
where in the SecondActivity do you declare button2?
you should do it in the onCreate method after setContentView()
and check your layout you are in SecondActivity if the button with that specific id "help" actually exists
Try the following
use the code following code
button2 = (Button)findViewById(R.menu.help);
instead of
button2 = (Button)findViewById(R.id.help);

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();
}

java.lang.RuntimeException: Unable to instantiate activity error

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" >

android newbie question null pointer on ArrayAdapter.setAdapter

I have been slowing learning and building my first android app. I'm VERY new to java but have already done a couple of projects in C#, VB.NET (back in the day), Objective-C (have 6 apps in the store) and Fortran (waaaaaaaaaaaaaaaaaaaay back in the day ;)
So I just received from overseas a htc legend (I'm not in the US), which i bought in order to have a decent mid-level device for development (it's running non-rooted adnroid 2.1)
The application I have been developing is target level 4 (android 1.6). It uses a 5 Mb sqlite3 database with a .mp3 extension to avoid compression within the apk and proper copying from assets to system folder.
It all works fine on the emulator, and on the device I see that the file size of the app after copying the database matches exactly what I see on the emulator.
now, on my main activity with a list view and a spinner, I bind some data through two array adapters. when running on the device all does smoothly. but when trying to run on the device this part of the code:
public class mainAct extends Activity implements OnItemSelectedListener, TextWatcher, OnItemClickListener
{
/** members */
//private EditText searchtext;
private ListView designations;
private ArrayAdapter<String> adapterShapes;
private ArrayAdapter<String> adapterTypes;
private Spinner types;
.
.
.
public void onCreate(Bundle savedInstanceState)
{
.
.
.
// DESIGNATIONS
//
adapterShapes = new ArrayAdapter<String>(this,R.layout.list_item,shapes); // custom TextView Adapter
designations=(ListView)findViewById(R.id.designations);
Log.e("MAIN.ACCT", "ok to 172");
designations.setAdapter(adapterShapes);
Log.e("MAIN.ACCT", "ok to 174");
designations.setOnItemClickListener(this);
// TYPES
//
adapterTypes=new ArrayAdapter<String>(this,R.layout.spinner_item,DT.get().typesInLibrary);
types=(Spinner)findViewById(R.id.types);
types.setAdapter(adapterTypes);
types.setOnItemSelectedListener(this);
.
.
.
}
}
Both designations.setAdapter(adapterShapes);
& types.setAdapter(adapterTypes);
give me a Null Pointer exception.
I'm using eclipse under mac, the LogCat window throws:
06-25 18:41:37.842:
ERROR/AndroidRuntime(9523): Uncaught
handler: thread main exiting due to
uncaught exception
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523):
java.lang.RuntimeException: Unable to
start activity
ComponentInfo{com.davidhomes.steel/com.davidhomes.steel.mainAct}:
java.lang.NullPointerException
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
android.app.ActivityThread.access$2200(ActivityThread.java:126)
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
android.os.Handler.dispatchMessage(Handler.java:99)
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
android.os.Looper.loop(Looper.java:123)
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
android.app.ActivityThread.main(ActivityThread.java:4595)
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
java.lang.reflect.Method.invokeNative(Native
Method)
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
java.lang.reflect.Method.invoke(Method.java:521)
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
dalvik.system.NativeStart.main(Native
Method)
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): Caused by:
java.lang.NullPointerException
-------------------------------------------------------------- 06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
com.davidhomes.steel.mainAct.onCreate(mainAct.java:183)
--------------------------------------------------------------
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
06-25 18:41:37.891:
ERROR/AndroidRuntime(9523): ... 11
more
06-25 18:46:38.252:
ERROR/ActivityManager(99): fail to set
top app changed!
Line 183 is the first setAdapter call (designations.setAdapter(adapterShapes);), when I comment it out the second setAdapter is the one breaking code
I'm a little lost here, the adapters show the proper number of items on the log window when running from the simulator and the device.
I admit to being a noob to both java and android, so any help is highly appreciated.
regards
david
Well, as you've probably figured out yourself, some variable is null. Unfortunately, there is no obvious source of the NullPointerException in your code.
Therefore, you should first try to identify what variable is null, and hence causing the exception.
For example, findViewById returns null if it cannot find the view, so you may want to double check your ListView and Spinner are being initialised properly.
Of course, the problem may be with your ArrayAdapters, so you should also check them, but from your question it sounds as if you've already done that.
Once you (and we) know exactly where the NullPointerException is occurring, it will be easier to give more specific advice
Oops! it was my fault all along, somehow I had TWO layouts (one for different resolutions), the one being used on my device did not have the proper ListView and Spinner ID. That alternative layout was collapse into a folder and I just forgot about it (I had paused development of the app for about 2 month until I actually got a device to test on).
the one working fine was installing on the simulator but not on the device and vice-versa, weird as the good one matches the resolution of my device (I'm pretty sure I'm also missing something there but that's not important right now)
Still, thanks Chris for pointing me to looking at the Null return value on findViewById. Being new to android I was lost as to were to begin
Best regards
david
I know this is a long closed subject. However I just came across the same problem and this post did not answer it.
What i did, was very silly. I forgot to add a reference to the xml. ie. setContentView(R.layout.settings);
it actually looks like the original post might have also forgotten this so i thought I would just post it.
Cheers.
I had the same problem. I put Log.d messages in printing out every object. It turned out that my ListView object was "null". The reason for this was I had the wrong XML activity listed in my SetContentView. I think the easiest way to debug this problem is keep putting in Log.d messages until you find the object/variable that is "null".

Categories

Resources