亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

java.lang.RuntimeException:無法實例化活動

java.lang.RuntimeException:無法實例化活動

繁花如伊 2023-08-16 17:50:28
單擊 AccountFragment 中的按鈕后出現此錯誤public class AccountFragment extends Fragment  {    private static final String TAG = "Profile" ;    FirebaseAuth firebaseAuth;    FirebaseUser currentUser;    DatabaseReference databaseReference;    TextView tv_name, tv_email, tv_gender, tv_home, tv_phone;    private String userID;    Button btn_update;    public AccountFragment() {        // Required empty public constructor    }    @Override    public View onCreateView(LayoutInflater inflater, ViewGroup container,                             Bundle savedInstanceState) {        // Inflate the layout for this fragment        View view = inflater.inflate(R.layout.fragment_account, container, false);        tv_name=view.findViewById(R.id.tv_name);        tv_email=view.findViewById(R.id.tv_email);        tv_gender=view.findViewById(R.id.tv_gender);        tv_home=view.findViewById(R.id.tv_home);        tv_phone=view.findViewById(R.id.tv_phone);        btn_update=view.findViewById(R.id.btn_update);        //ini        firebaseAuth = FirebaseAuth.getInstance();        currentUser = firebaseAuth.getCurrentUser();        userID = currentUser.getUid();        databaseReference = FirebaseDatabase.getInstance().getReference("Customer").child(firebaseAuth.getUid());        //For Retrieve Information        databaseReference.addValueEventListener(new ValueEventListener() {            @Override            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {                Log.d( TAG, "onDataChange :" +dataSnapshot);                    Customer cust = dataSnapshot.getValue(Customer.class);                    tv_name.setText(cust.getName());                    tv_email.setText(cust.getEmail());                    tv_gender.setText(cust.getGender());                    tv_home.setText(cust.getHome_address());                    tv_phone.setText(cust.getTelephone_number());            }單擊按鈕后,我收到此錯誤 2019-09-22 22:20:32
查看完整描述

1 回答

?
智慧大石

TA貢獻1946條經驗 獲得超3個贊

您無法使用 startActivity 打開片段,您需要實現一個回調,該回調會在您的用戶個人資料成功更新時觸發。在您的主機活動中創建一個界面,如下所示:


public interface UpdateProfileSuccess{

    void presentAccountFragment();

}

還在活動中將其實例化為:


UpdateProfileSuccess callback = new UpdateProfileSuccess(){

@Override

void presentAccountFragment(){

getSupportFragmentManager().beginTransaction().replace(R.id.container,new 

        AccuontFragment()).commit();

    }

}

在您的更新配置文件片段中,創建一個構造函數,將該回調作為:


private MainActivity.UpdateProfileSuccess callback;

public UpdateProfileFragment(MainActivity.UpdateProfileSuccess callback){

    this.callback = callback;

}

最后在請求的 onComplete 中將該回調消耗為:


callback.presentAccountFragment();

這樣您的 Activity 將負責呈現 AccountFragment。


查看完整回答
反對 回復 2023-08-16
  • 1 回答
  • 0 關注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號