从导航抽屉调用活动Base Fragment类提供异常

时间:2015-10-21 07:25:09

标签: android android-fragments android-activity nullpointerexception navigation-drawer

 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.activity_wollet, container, false);

    findViewIds(v);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            amount = et_amount.getText().toString().trim();
            if (isValidPassword() == false) {

                Intent intent = new Intent(getActivity(),PayMentGetWay2.class);
                try{
                startActivity(intent);
                }catch(Exception e)
                {
                    ;
                }

            }

        }
    });

      return v;
}

private void findViewIds(View v) {
    button = (Button) v.findViewById(R.id.bt_addWallet);
    et_amount = (EditText) v.findViewById(R.id.et_amount);
}

// validating password with retype password
private boolean isValidPassword() {
    if (amount.equalsIgnoreCase("")) {
        Toast.makeText(getActivity().getBaseContext(), "Plz Enter Amount", 0)
                .show();
        return true;
    }
    return false;
}

这是我的代码我试图从call a activity base fragment class但它会崩溃应用程序。我的日志cat错误输出如下 -

10-21 12:44:44.153: E/AndroidRuntime(3464): FATAL EXCEPTION: main
10-21 12:44:44.153: E/AndroidRuntime(3464): Process: com.yash.desirechargeapps, PID: 3464
10-21 12:44:44.153: E/AndroidRuntime(3464): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.yash.desirechargeapps/com.yash.desirechargeapps.PayMentGetWay2}: java.lang.NullPointerException
10-21 12:44:44.153: E/AndroidRuntime(3464):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
10-21 12:44:44.153: E/AndroidRuntime(3464):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
10-21 12:44:44.153: E/AndroidRuntime(3464):     at android.app.ActivityThread.access$800(ActivityThread.java:151)
10-21 12:44:44.153: E/AndroidRuntime(3464):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
10-21 12:44:44.153: E/AndroidRuntime(3464):     at android.os.Handler.dispatchMessage(Handler.java:110)
10-21 12:44:44.153: E/AndroidRuntime(3464):     at android.os.Looper.loop(Looper.java:193)
10-21 12:44:44.153: E/AndroidRuntime(3464):     at android.app.ActivityThread.main(ActivityThread.java:5299)
10-21 12:44:44.153: E/AndroidRuntime(3464):     at java.lang.reflect.Method.invokeNative(Native Method)
10-21 12:44:44.153: E/AndroidRuntime(3464):     at java.lang.reflect.Method.invoke(Method.java:515)
10-21 12:44:44.153: E/AndroidRuntime(3464):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
10-21 12:44:44.153: E/AndroidRuntime(3464):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
10-21 12:44:44.153: E/AndroidRuntime(3464):     at dalvik.system.NativeStart.main(Native Method)
10-21 12:44:44.153: E/AndroidRuntime(3464): Caused by: java.lang.NullPointerException
10-21 12:44:44.153: E/AndroidRuntime(3464):     at com.yash.desirechargeapps.PayMentGetWay2.onCreate(PayMentGetWay2.java:39)
10-21 12:44:44.153: E/AndroidRuntime(3464):     at android.app.Activity.performCreate(Activity.java:5264)
10-21 12:44:44.153: E/AndroidRuntime(3464):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
10-21 12:44:44.153: E/AndroidRuntime(3464):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
10-21 12:44:44.153: E/AndroidRuntime(3464):     ... 11 more

我试图搜索,但我不明白究竟是什么问题。我认为获取活动存在一些问题,但我无法弄明白。我也提到了清单中的活动。我是新手,请帮助我。

1 个答案:

答案 0 :(得分:0)

你好这回答我自己的问题很奇怪,但是我发现我的问题的答案实际上是空的指针异常在我呼叫的my activity class中引发,我错过了那里的东西。这就是我在片段中获得null pointer and class not found exception的原因。