I am trying to make a PopupWindow
to explain my app, however I am having a lot of difficulty for a seemingly simple thing. I tried various youtube videos and looked at almost all the similar posts on here about it, but I haven't had any luck yet. If someone can please point out my flaw, that'd be great.
My end goal is for the PopupWindow to appear with the on create method, but I included a Button to start it for now because all the tutorials included one.
protected void onCreate(Bundle savedInstanceState) {
//BUILDING THE POP UP WINDOW ON CLICK OF HELP BUTTON
help=(Button)findViewById(R.id.help);
help.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
layoutInflater=(LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View customView= layoutInflater.inflate(R.layout.activity_instructions, null);
popUpWindow=new PopupWindow(
customView,
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popUpWindow.dismiss();
}
});
}
});
Any help would be greatly appreciated. If I need to include any more information, please do ask. I am new to android and this is my first big Application so keeping my hopes up.
Thanks The link to my log
07-30 23:32:07.062 9273-9273/my.myCompany.vinay.diversityformulaapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: my.myCompany.vinay.diversityformulaapplication, PID: 9273
java.lang.RuntimeException: Unable to start activity ComponentInfo{my.myCompany.vinay.diversityformulaapplication/my.myCompany.vinay.diversityformulaapplication.EntryScreen}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3008)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at my.myCompany.vinay.diversityformulaapplication.EntryScreen.onCreate(EntryScreen.java:37)
at android.app.Activity.performCreate(Activity.java:6912)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2900)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3008)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)