0

こんにちは私はダイアログフラグメントを書いていて、getArgumentsとsetArgumentsを使用していくつかのデータを渡そうとしていますが、getArgumentsを使用してデータを取得しているときにNPEを取得します。

public class EditNameDialog extends DialogFragment{


public static EditNameDialog newInstance(int type){

    EditNameDialog thedialog=new EditNameDialog();
    Bundle bundle=new Bundle();
    Log.v("typ",type+"");//-->logs fine here
    bundle.putInt("mytype", type);
    thedialog.setArguments(bundle);
    return thedialog;

}



public Dialog onCreateDialog(Bundle icic){

    String ok="Play";
 //I get a NPE here in the below line
    switch(getArguments().getInt("mytype")){ 

    case 1:
    case 2:
        ok="Play";
        break;
    case 3:
        ok="Show";
        break;
    case 4:
        ok="Show";
        break;

    }
    //show alert dialog etc etc here

}

 }

誰かがこれを見て、私がここで何が欠けているのか教えてもらえますか?

編集:-これは私がdialogfragmentを呼び出す方法です:-

 DialogFragment newFragment = EditNameDialog.newInstance(1);
 newFragment.show(getSupportFragmentManager(), "mydialog");

LogCatは次のようになります:-

01-14 12:52:58.557: E/AndroidRuntime(17271): FATAL EXCEPTION: main
01-14 12:52:58.557: E/AndroidRuntime(17271): java.lang.NullPointerException
01-14 12:52:58.557: E/AndroidRuntime(17271):    at com.civil.dialogs.EditNameDialog.onCreateDialog(EditNameDialog.java:79)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:295)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at android.os.Handler.handleCallback(Handler.java:725)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at android.os.Looper.loop(Looper.java:137)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at android.app.ActivityThread.main(ActivityThread.java:5039)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at java.lang.reflect.Method.invokeNative(Native Method)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at java.lang.reflect.Method.invoke(Method.java:511)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-14 12:52:58.557: E/AndroidRuntime(17271):    at dalvik.system.NativeStart.main(Native Method)
4

0 に答える 0