2011-06-20 12 views
0

私のコードは次のようである - 私は私のFacebookのプロファイルデータ などなどの名前、電子メールなどを取得しようとすると、私自身のUI上 として、それを交換したいのです。
私は私は私の状態が保存されているので、私は、何をすべきsetText(b.getString(key)); を呼び出したときに、今、私はonCreate()を使用していない実際のデータ.sinceと私のUI を更新したい、私はNPE を取得しています、データをフェッチすることができていますon Bundle b オーバーライドonCreate()はオプションのようですか?任意のヘルプ? 変更TextViewには

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

    } 


} 
+0

b.getString(key)の呼び出しがnullを返すことを意味しますか? – Audrius

+0

レイアウトXMLはどのように見えますか? – diagonalbatman

+0

@ Audriusの場合は、String name = bを使用します。 getString(key);それは私の名前を返しますので、私は文字列を持って、私自身の宇井 – vibhor

答えて

0

UIスレッド以外のスレッドがProfileInfoAvailableメソッドを実行していないことを確認する必要があります。あなたは活動のonCreate方法は、常にUIスレッド上で実行され

runOnUiThread(new Runnable() { 
    public void run() { 
     mFirstNameTextBox.setText(b.getString(key)); 
    } 
} 

次のコードを使用してこれを確認することができます。あなたはこれを使用したい場合は、アクティビティを起動し、あなたのonCreateメソッドでそれを読むためにこの

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    Bundle extras = this.getIntent().getExtras(); 
    if (extras != null && extras.containsKey("name")) { 
     String userName = this.getIntent().getExtras().getString("name"); 
    } 
} 

のようなものを使用するには、この

Intent i = new Intent(CurrentIntent.this, NewIntentToLaunch.class); 
i.putExtra("name", userName); 
...add more data 
startActivity(i); 

のようなものを追加します。