0

私が作成したトーストのテーマを保存し、トーストを作成するためのクラスに取り組んでいます。現在、フラグメントでテストしているため、静的である必要があると思います。問題は、アプリケーション コンテキストを渡す方法がわからないことです。次のエラーが表示されます。

Cannot make a static reference to the non-static method getApplicationContext() from the type ContextWrapper

このエラーが発生する理由は理解していますが、正しい方法がわかりません。フォーラムで同様のエラーを検索しましたが、答えが見つかりませんでした。

public class MainActivity extends FragmentActivity 
        implements ActionBar.OnNavigationListener {

    private static DWAWebGet webGet = new DWAWebGet();

    private static DWAToaster toaster = 
        new DWAToaster(getApplicationContext())
            .makeToast("error",Toast.LENGTH_LONG,Gravity.TOP,0,0)
            .makeToast("alert",Toast.LENGTH_SHORT,Gravity.TOP,0,0)
            .makeToast("msg",Toast.LENGTH_SHORT,Gravity.TOP,0,0);

    ...

    public static class SectionFragment_sign_in extends Fragment {

        ...

        public void click_register_button(View view) {

            TextView email_TextView = (TextView) view.findViewById(R.id.register_email_input);
            TextView pass1_TextView = (TextView) view.findViewById(R.id.register_pass1_input);
            TextView pass2_TextView = (TextView) view.findViewById(R.id.register_pass2_input);

            String email = email_TextView.getText().toString();
            String pass1 = pass1_TextView.getText().toString();
            String pass2 = pass2_TextView.getText().toString();

            webGet.waitGet(
                    "https",
                    "...",
                    "/app/menu/data/register/",
                    "email="+webGet.encode(email)
                    +"&pass1="+webGet.encode(pass1)
                    +"&pass2="+webGet.encode(pass2),
                    new RegisterResponseHandler(),
                    toaster
                    );

        }

        public class RegisterResponseHandler 
                extends DWAWebGet.Handler<DWAWebGet.Response> {

            public RegisterResponseHandler () {
                new DWAWebGet().super();
            }

            public void handle (DWAWebGet.Response r) {

                String status;
                String error;

                if ((status = r.getMap("status").getStr()) == null) {
                    toaster.error("Response Status: null");
                } else if (status == "denied") {
                    if ((error = r.getMap("error").getStr()) == null) error = "No Reason Given";    
                    toaster.alert("Registration Denied: " +  error);
                } else if (status != "good") {
                    if ((error = r.getMap("error").getStr()) == null) error = "blank";
                    toaster.error("Response Status: " + status + ", Error: "+error);
                } else {
                    toaster.msg("Registration Complete. Please check your email and verify your email address.");
                    ((MainActivity) SectionFragment_sign_in .this.getActivity())
                .prefs_edit.putString("id_email",r.getMap("email").getStr());
                    ((TextView) ((MainActivity) SectionFragment_sign_in .this.getActivity())
                            .findViewById(R.id.sign_in_email_input))
                            .setText(r.getMap("email").getStr());
                }

            }

        }
    }
}
4

0 に答える 0