我在解析时有一个java bean类设置值。我需要访问这个类 全局但在使用其实例静态时给出空指针异常并在其中赋值.Code为: -
private String Responce;
private String Error;
private String Url;
private SIPModle objsip;
private VMModle objvmmodle;
private ArrayList<CustompadModle> objcmodlelist = new ArrayList<CustompadModle>();
private SettingModle objsettingmodle;
private WifiModle objwifimodle;
public String getResponce() {
return Responce;
}
public void setResponce(String responce) {
Responce = responce;
}
public String getError() {
return Error;
}
public void setError(String error) {
Error = error;
}
public ArrayList<CustompadModle> getObjcmodlelist() {
return objcmodlelist;
}
public void setObjcmodlelist(CustompadModle objcmodlelist) {
this.objcmodlelist.add(objcmodlelist);
}
public String getUrl() {
return Url;
}
public void setUrl(String url) {
Url = url;
}
public SIPModle getObjsip() {
return objsip;
}
public void setObjsip(SIPModle objsip) {
this.objsip = objsip;
}
public VMModle getObjvmmodle() {
return objvmmodle;
}
public void setObjvmmodle(VMModle objvmmodle) {
this.objvmmodle = objvmmodle;
}
public SettingModle getObjsettingmodle() {
return objsettingmodle;
}
public void setObjsettingmodle(SettingModle objsettingmodle) {
this.objsettingmodle = objsettingmodle;
}
public WifiModle getObjwifimodle() {
return objwifimodle;
}
public void setObjwifimodle(WifiModle objwifimodle) {
this.objwifimodle = objwifimodle;
}
我的要求是全球访问这个bean类全球。任何人建议我
我在doinbackground中获取此对象,并将该类的静态对象分配为: AsyncTask {
ProgressDialog objprogress = new ProgressDialog(
UserSettingConfiguration.this);
ApplicationRequestHandler objhandler = new ApplicationRequestHandler();
@Override
protected void onPreExecute() {
this.objprogress.setMessage("Please Wait While Loading...");
this.objprogress.isShowing();
}
@Override
protected ConfigurationSttingModle doInBackground(String... params) {
objconfigsetting = objhandler.getConfigurationSetting(params[0],
params[1], params[2], params[3]);
return objconfigsetting;
}
@Override
protected void onPostExecute(ConfigurationSttingModle result) {
if (this.objprogress.isShowing()) {
this.objprogress.dismiss();
}
}
}
并在课程中使用Advance作为; -
private static HashMap<String, String> SUMMARIES = new HashMap<String, String>() {
private static final long serialVersionUID = 3055562364235868653L;
{
String server = UserSettingConfiguration.objconfigsetting.getObjsip().getServer();
String displayname1 = UserSettingConfiguration.objconfigsetting.getObjsip().getUser();
String user = UserSettingConfiguration.objconfigsetting.getObjsip().getUser();
String password= UserSettingConfiguration.objconfigsetting.getObjsip().getPassword();
put(FIELD_DISPLAY_NAME,displayname1);// "90901");
put(FIELD_CALLER_ID,displayname1); //"90901");
put(FIELD_SERVER,server);
put(FIELD_USERNAME,user);
put(FIELD_AUTH_ID, "207");
put(FIELD_PASSWORD,password);
put(FIELD_PROXY, null);
}
};
答案 0 :(得分:1)
我认为单身模式符合您的要求。
您必须添加以下代码:
private static MyJavaBeanClass = null;
public static MyJavaBeanClass getInstance(){
if(null == instance){
instance = new MyJavaBeanClass();
}
return instance;
}
您必须更改MyJavaBeanClass作为您的类的名称,然后您可以在任何地方调用它:
MyJavaBeanClass.getInstance().setError("Testing");