0

私はポップアップ ウィンドウで作業しています。onclick でエラーが発生する理由がわかりません。以下は私のコードです:

protected void popup() {

RelativeLayout viewGroup(RelativeLayout)MainActivity.this.findViewById(R.id.popup); 
LayoutInflater layoutInflater = (LayoutInflater)MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup, viewGroup);
final PopupWindow popup = new PopupWindow(this);
popup.setContentView(layout);

popup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
popup.setBackgroundDrawable(null);
popup.setFocusable(true);   
popup.showAtLocation(layout, Gravity.CENTER, 1, 1);
popcash = (ImageButton )findViewById(R.id.popcash);
popcash.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {


        Toast.makeText(getApplicationContext(), "on click image button", Toast.LENGTH_LONG).show();

    }
});

popcoin = (ImageButton) findViewById(R.id.popcoin);
popcoin.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        Log.e("hi", "there");

    }
});



}

しかし、私は次のエラーが発生しています

04-25 17:18:13.856: E/AndroidRuntime(1521): java.lang.NullPointerException
04-25 17:18:13.856: E/AndroidRuntime(1521):     at         com.example.scratchcarddemo.MainActivity.popup(MainActivity.java:304)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at com.example.scratchcarddemo.MainActivity$2.onTouch(MainActivity.java:225)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at android.view.View.dispatchTouchEvent(View.java:3762)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at     com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1655)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1785)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at android.os.Looper.loop(Looper.java:123)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at android.app.ActivityThread.main(ActivityThread.java:4627)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at java.lang.reflect.Method.invokeNative(Native Method)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at java.lang.reflect.Method.invoke(Method.java:521)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-25 17:18:13.856: E/AndroidRuntime(1521):     at dalvik.system.NativeStart.main(Native Method)
4

2 に答える 2