我在片段中有一个2维的int数组,带有他的getter,如下所示:
public class AddMatriceCalc extends Fragment {
private static int [][] matriceRes = new int[MatriceActivity.n][MatriceActivity.n];
public static int[][] getMatriceResAM() {
return matriceRes;
}
...
我想在另一个片段中使用getter,但它不起作用。当我在没有getter(public static int [][] matriceRes = new int[MatriceActivity.n][MatriceActivity.n]
)的情况下使用 matriceRes 时,它可以工作,但是当我使用getter时它不起作用:
我的第二个片段:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.add_matrice_result, container, false);
layoutResultCalc = (LinearLayout) v.findViewById(R.id.LayoutMatriceRes);
reloadAddMatrice = (Button) v.findViewById(R.id.reloadAddMatrice);
reloadAddMatrice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//ON RELANCE LA DEMANDE DE TAILLE DE MATRICE
final Dialog matricesize = new Dialog(getContext());
matricesize.setContentView(R.layout.dialogmatricesize);
Button dialogbutton = (Button) matricesize.findViewById(R.id.closedialog);
dialogbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText editsizel = (EditText) matricesize.findViewById(R.id.editsizel);
EditText editsizeh = (EditText) matricesize.findViewById(R.id.editsizeh);
MatriceActivity.n = Integer.parseInt(editsizel.getText().toString());
MatriceActivity.m = Integer.parseInt(editsizeh.getText().toString());
matricesize.dismiss();
//MISE A ZERO DE TOUTES LES VALEURS, LES TABLEAUX, ...
//PUIS ON VA AU TAB CALC
i = 0;
j = 0;
l = 0;
AddMatriceCalc.getLayoutmap1AM().clear();
AddMatriceCalc.getLayoutmap2AM().clear();
AddMatriceCalc.getEdittextmap1AM().clear();
AddMatriceCalc.getEdittextmap2AM().clear();
layoutresmap.clear();
layoutreslist.clear();
textviewreslist.clear();
textviewresmap.clear();
AddMatriceCalc.getMatriceResAM() = null;
layoutResultCalc.removeAllViews();
AddMatriceCalc.getLayoutmatrice1AM().removeAllViews();
AddMatriceCalc.getLayoutmatrice2AM().removeAllViews();
AddMatriceCalc.getViewpagerAM().setCurrentItem(1);
}
});
int dialogwidth = (int) getResources().getDimension(R.dimen.width_matrice);
int dialogheight = (int) getResources().getDimension(R.dimen.height_matrice);
matricesize.getWindow().setLayout(dialogwidth, dialogheight);
matricesize.setTitle("Taille des matrices");
matricesize.show();
}
});
return v;
}
第AddMatriceCalc.getMatriceResAM() = null;
行错误预期变量但是当我在没有getter的情况下公开使用matriceRes时就可以了。
你能告诉我为什么吗?
谢谢