Android:无法实例化活动组件信息

时间:2013-12-19 02:08:11

标签: android eclipse facebook facebook-graph-api nullpointerexception

我尝试制作包含事件和邀请朋友的Android应用程序,所以当我开始活动时,一开始就创建好的所有因为我的静态变量 StaticAppointment.friendContactList.size() 坚持null (之前在活动中初始化),然后当我点击此活动上的按钮是,它将带我登录激活并授予Facebook创建和事件的许可,在Facebook上授予权限后按OK我假设它会将数据恢复到我的活动onActivityResults()< - CMIIW ,然后我的活动突然重启,因此我的var StaticAppointment.friendContactList.size() null再次 .. 我的问题是这是怎么发生的?当我的活动重启或者我不知道简历可能时,避免我的变量的可能解决方案是 not null ?请问我是开发Android应用程序的新手,抱歉我的英语不好因为我是亚洲人...而且还有帮助... ...

这是错误:

12-19 08:27:15.257: E/AndroidRuntime(8311): FATAL EXCEPTION: main
12-19 08:27:15.257: E/AndroidRuntime(8311): java.lang.RuntimeException: Unable to start             activity ComponentInfo{com.pjb.meetapps2/com.pjb.meetapps2.ConfirmationActivity}:     java.lang.NullPointerException
12-19 08:27:15.257: E/AndroidRuntime(8311): Caused by: java.lang.NullPointerException
12-19 08:27:15.257: E/AndroidRuntime(8311): at com.pjb.meetapps2.ConfirmationActivity.onCreate(ConfirmationActivity.java:101)

这是活动(对不起,我的活动很长,我已经削减了一些不相关的部分):

public class ConfirmationActivity extends Activity {
// =================================
// Variables
// =================================

/*
 * Data
 */
private String nameAppnt = "";
private String descAppnt = "";
public int dateAppointment = -1;
public int monthAppointment = -1;
public int yearAppointment = -1;
public int hourAppointment = -1;
public int minuteAppointment = -1;

private List<Friend> friendContactList = null;
private int alarmAppnt = -1;
private boolean fbSharing = false;
private boolean smsSharing = false;
private String[] itemsFriends;
private AppointmentDAO mDao;

/*
 * Views
 */
private TextView lblName;
private TextView lblDateTime;
private TextView lblAlarm;
private TextView lblFB;
private TextView lblSMS;
private Button btnShowFriend;
private Button btnYes;
private Button btnNo;
private EditText txtDesc;
private SmsManager smsMgr;

/*
 * Alarm
 */
AlarmManager alarmManager;

// =================================
// Activity Life Cycle Methods
// =================================

public static final String APP_ID = "385248281609371";
protected static final String TAG = "Meets";
String message ="";
private String[] dataId;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.confirmation);
    //this is line 101 the error
    itemsFriends = new String[StaticAppointment.friendContactList.size()];
    lblName = (TextView) findViewById(R.id.txtConfName);
    lblDateTime = (TextView) findViewById(R.id.txtConfDateTime);
    lblAlarm = (TextView) findViewById(R.id.txtConfAlarm);
    lblFB = (TextView) findViewById(R.id.txtConfFacebook);
    lblSMS = (TextView) findViewById(R.id.txtConfSMS);
    btnShowFriend = (Button) findViewById(R.id.btnConfShowFriend);
    btnYes = (Button) findViewById(R.id.btnConfYes);
    btnNo = (Button) findViewById(R.id.btnConfNo);
    txtDesc = (EditText) findViewById(R.id.txtConfDesc);

    mDao = new AppointmentDAO(this);
    mDao.openConnection();
    smsMgr = SmsManager.getDefault();
    btnYes.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            actionYes();
        }
    });
@Override
protected void onResume() {
    if (mDao != null)
        mDao.openConnection();
    super.onResume();
}

@Override
protected void onRestart() {
    if (mDao != null)
        mDao.openConnection();
    super.onRestart();
}

@Override
protected void onPause() {
    if (mDao != null)
        mDao.closeConnection();

    super.onPause();
}

@Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    super.onBackPressed();
}

这是actionyes方法:

private void actionYes() {

    int id = 0;

    if (!StaticAppointment.isEditMode) {

        int lastId = mDao.getMaxID();
        if (lastId < 0) {
            lastId = 0;
        }

        id = ++lastId;

    } else {

        id = StaticAppointment.currentAppointment.id;
    }
    StaticAppointment.currentAppointment = new Appointment();
    StaticAppointment.currentAppointment.id = id;
    StaticAppointment.currentAppointment.nameAppointment = nameAppnt;
    StaticAppointment.currentAppointment.descAppointment = descAppnt;

    StaticAppointment.currentAppointment.dateAppointment = StaticAppointment.dateAppointment;
    StaticAppointment.currentAppointment.monthAppointment = StaticAppointment.monthAppointment;
    StaticAppointment.currentAppointment.yearAppointment = StaticAppointment.yearAppointment;
    StaticAppointment.currentAppointment.hourAppointment = StaticAppointment.hourAppointment;
    StaticAppointment.currentAppointment.minuteAppointment = StaticAppointment.minuteAppointment;

    StaticAppointment.currentAppointment.friendContactList = StaticAppointment.friendContactList;
    StaticAppointment.currentAppointment.alarmMinutes = StaticAppointment.alarmMinutes;
    StaticAppointment.currentAppointment.fbSharing = StaticAppointment.fbSharing;
    StaticAppointment.currentAppointment.smsSharing = StaticAppointment.smsSharing;
    StaticAppointment.currentAppointment.locationName = StaticAppointment.locationName;
    StaticAppointment.currentAppointment.longitude = StaticAppointment.longitude;
    StaticAppointment.currentAppointment.latitude = StaticAppointment.latitude;
    StaticAppointment.currentAppointment.fbEventid = StaticAppointment.fbEventId;

    for (int i = 0; i < friendContactList.size(); i++) {
        friendContactList.get(i).id = StaticAppointment.currentAppointment.id;
    }
    StaticAppointment.friendContactList = this.friendContactList;

    dateTime = dateAppointment + "-" + (monthAppointment + 1) + "-"
            + yearAppointment + ", " + hourAppointment + ":"
            + minuteAppointment;

    if (StaticAppointment.currentAppointment.fbSharing) {
        System.out.println("fb sharing nyala");
        try {
            postToFB();
        } catch (Exception e) {
            e.printStackTrace();
        }

    } else {
        StaticAppointment.currentAppointment.fbEventid = "noFB";
        if (StaticAppointment.currentAppointment.smsSharing) {
            System.out.println("sms sharing nyala");
            sendSms("noFB");
        }
        dbAction();
    }

    clearTempData();
}

,这是facebook权限:

private void postToFB() {

    //System.out.println("BURUK tidak bisa login");
    //Utility.showAlert(this, "Warning", "You must first log in.");
        List<String> permission = new ArrayList<String>();
        permission.add("publish_stream");
        permission.add("create_event");
        permission.add("publish_checkins");
        Session session = Session.getActiveSession();

        if (session != null){

            // Check for publish permissions    
            List<String> permissions = session.getPermissions();
            if (!isSubsetOf(permission, permissions)) {
                Session.NewPermissionsRequest newperreq = new  Session.NewPermissionsRequest(this, permission);
                session.requestNewPublishPermissions(newperreq);
            }
           // doGetEvent();
            checkIn();
        }

}

0 个答案:

没有答案