Android 我的对话框联机工作,但脱机时不工作

Android 我的对话框联机工作,但脱机时不工作,android,Android,我有一个公司列表,我正在打开一个对话框登录特定的公司。这在网上运行良好。现在,我的要求是将此应用程序脱机。当我点击列表中的某一行时,我会在应用程序离线时崩溃并抛出充气装置。 这是我的对话方法 public void showDialog(){ dialog = new Dialog(context); dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.la

我有一个公司列表,我正在打开一个对话框登录特定的公司。这在网上运行良好。现在,我的要求是将此应用程序脱机。当我点击列表中的某一行时,我会在应用程序离线时崩溃并抛出充气装置。 这是我的对话方法

public void showDialog(){
    dialog = new Dialog(context);
    dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_login);
    dialog.setCancelable(true);
    // set the custom dialog components - text, image and button
    EditText username = (EditText) dialog.findViewById(R.id.cusername);
    EditText password = (EditText) dialog.findViewById(R.id.cpassword);
    CheckBox checkBox = (CheckBox) dialog.findViewById(R.id.remember_password);
    LinearLayout submit = (LinearLayout) dialog.findViewById(R.id.submit);
    LinearLayout close = (LinearLayout) dialog.findViewById(R.id.close);
    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            InputMethodManager inputManager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(view.getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
            dialog.dismiss();
        }
    });

    for (int i = 0; i < appUser.companyLoginArray.size(); i++) {
        Map map = appUser.companyLoginArray.get(i);
        String position = (String) map.get("position");
        if (pos == Integer.parseInt(position)) {
            Boolean status = (Boolean) map.get("status");
            String uName = (String) map.get("username");
            String pass = (String) map.get("password");
            if (status) {
                checkBox.setChecked(true);
                username.setText(uName);
                password.setText(pass);
            }
        }

    }
    // if button is clicked, close the custom dialog
    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            InputMethodManager inputManager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(v.getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
            appUser.boolSetOrAddtoMap=false;
            appUser.company_logo=data.get(pos).getAttributes().getLogo();
            appUser.company_state=data.get(pos).getAttributes().getState();
            LocalRepositories.saveAppUser(context,appUser);
            Map mapAdd= new HashMap();
            if (!username.getText().toString().equals("")) {
                if (!password.getText().toString().equals("")) {
                    appUser.cusername = username.getText().toString();
                    appUser.cpassword = password.getText().toString();
                    LocalRepositories.saveAppUser(context, appUser);
                    dialog.dismiss();

                    if (checkBox.isChecked()) {


                        mapAdd.put("position", String.valueOf(pos));
                        mapAdd.put("username", username.getText().toString());
                        mapAdd.put("password", password.getText().toString());
                        mapAdd.put("status", true);

                        for (int i=0;i<appUser.companyLoginArray.size();i++){
                            Map mapGet=appUser.companyLoginArray.get(i);
                            String str= (String) mapGet.get("position");
                            Integer integer= Integer.valueOf(str);
                            if (integer==Integer.valueOf(pos)){
                                LocalRepositories.saveAppUser(context,appUser);
                                appUser.companyLoginArray.set(i,mapGet);
                                LocalRepositories.saveAppUser(context, appUser);
                            }
                        }
                        if (!appUser.boolSetOrAddtoMap){
                            appUser.companyLoginArray.add(mapAdd);
                            LocalRepositories.saveAppUser(context, appUser);
                        }
                    } else {
                        for (int i = 0; i < appUser.companyLoginArray.size(); i++) {
                            Map mapRemove = appUser.companyLoginArray.get(i);
                            String position = (String) mapRemove.get("position");
                            if (pos ==Integer.valueOf(position)) {
                                appUser.companyLoginArray.remove(i);
                                LocalRepositories.saveAppUser(context, appUser);
                            }
                        }
                    }
                    EventBus.getDefault().post(new EventOpenCompany(pos));

                } else {
                    Toast.makeText(context, "Enter password", Toast.LENGTH_LONG).show();
                }
            } else {
                Toast.makeText(context, "Enter username", Toast.LENGTH_LONG).show();
            }
        }
    });

    dialog.show();
}
public void showDialog(){
对话框=新对话框(上下文);
dialog.getWindow().requestFeature(Window.FEATURE\u NO\u TITLE);
setContentView(R.layout.dialog\u登录);
对话框。可设置可取消(true);
//设置自定义对话框组件-文本、图像和按钮
EditText用户名=(EditText)dialog.findViewById(R.id.cusername);
EditText密码=(EditText)dialog.findViewById(R.id.cpassword);
CheckBox=(CheckBox)dialog.findviewbyd(R.id.memory\u password);
LinearLayout submit=(LinearLayout)dialog.findviewbyd(R.id.submit);
LinearLayout close=(LinearLayout)dialog.findViewById(R.id.close);
close.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
InputMethodManager inputManager=(InputMethodManager)context.getSystemService(context.INPUT\u方法\u服务);
inputManager.hideSoftInputFromWindow(view.getWindowToken(),
InputMethodManager.HIDE(不总是);
dialog.dismise();
}
});
对于(int i=0;i对于(int i=0;iYou应该发布logcat输出。布局填充与internet无关,它与您的代码有关。您应该检查您的代码是否未在脱机时执行internet操作或firebase操作是的,先生,我知道布局膨胀与网络连接无关。但我真的对这个错误感到震惊或者.android.view.InflateException:二进制XML文件行#1:膨胀类时出错,但此代码正在网络连接中运行。您的XML文件似乎包含不存在的视图类型。您确定在应用程序脱机联机时膨胀相同的布局吗?因为错误说明inflator尝试膨胀未知类。是的,我是100%你问的是真的吗?实际上,我用一个方法编写代码,我在离线和在线调用相同的方法。