My code is like this —
I am trying to fetch my facebook profile data
such as name , email etc and want to replace it as
on my own UI.
I am able to fetch the data , now i want to update my UI
with a real data .since i am not using onCreate() , i am getting NPE
when i called setText(b.getString(key));
what should i do , since my state is saved on Bundle b
so overrriding onCreate() doesnt seems to an option ??
any help ??
package com.android.soapbox;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import com.android.soapbox.SoapboxApplication.ProfileEventListener;
public class ProfileInfoListner extends Activity implements ProfileEventListener
{
public TextView mFirstNameTextBox ;
public TextView mLastNameTextBox ;
public void ProfileInfoAvailable(Bundle b)
{
Log.e("Facebook-Example", "Login_sucess");
//Go though all the info in the bundle and display
try
{
for (String key : b.keySet())
{
if(key.compareTo(SoapboxApplication.FIRST_NAME) == 0)
{
Log.e("Facebook-Example", "Log-Printed");
//Assuming mFirstNameTextBox points to the textbox on PRofile screen
if(mFirstNameTextBox!=null)
{
Log.e("Facebook-Example", "nnF");
// NPE
mFirstNameTextBox.setText(b.getString(key));
}
}
}
}
catch(NullPointerException c)
{
Log.e("ERROR","NPE2"+c.fillInStackTrace());
}
}
}
You have to make sure that no other thread than the UI thread is executing your
ProfileInfoAvailablemethod. You can make sure of this by using the following codeThe
onCreatemethod of an Activity is always run on the UI thread. If you want to use this, add something like thisto launch the activity and use something like this
to read it in your onCreate method.