2012-05-05 176 views
-1

我正在爲我的學位構建一個android應用程序。我需要從手機獲取所有聯繫人 開始申請(稍後我還需要獲得電子郵件etcetc)。所以我用了兩個類無法啓動活動ComponentInfo:java.lang.NullPointerException

Degree_thesisActivity

public class Degree_thesisActivity extends Activity { 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    GetFromPhone gf = new GetFromPhone(); 
    gf.getContacts(); 

} 

}

GetFromPhone.java

class GetFromPhone extends Activity { 

public void getContacts() { 
    // TODO Auto-generated method stub 


    /**Declare a Contacts Cursor which have a list of all contacts*/ 
    Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); 
    /**Move while cursor has another istance to process*/ 
    while(cursor.moveToNext()){ 
     /**Get the contact name pointed by cursor at that time*/ 
     cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); 
     String contactID = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); 
     /**show the contact pointed.THIS WILL BE MODIFIED FURTHER!!!!*/ 
       new AlertDialog.Builder(this) 
        .setMessage(contactID) 
        .setNeutralButton("ok", new OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 
          // TODO Auto-generated method stub 

         } 
        }) 
        .show(); 

    } 

} 

}

,但我得到這個錯誤:

05-05 15:49:20.060:E/AndroidRuntime(824):java.lang.RuntimeException:無法啓動活動ComponentInfo {it.paki.degreethesis/it.paki.degreethesis.Degree_thesisActivity}:java.lang.NullPointerException

爲什麼?有人可以幫助我嗎?

+0

請在您的logcat中發佈所有錯誤。 – Sam

回答

相關問題