###前提・実現したいこと
https://qiita.com/nein37/items/cc4fe1dc4f9527f8dd59
を参考にしてポップアップウィンドウをアプリを開けた瞬間に出るようにしたい。
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
popup(v);
}
でView v を必要とするプログラムは動くのか知りたいです。
(動くならどうやってやるのかも)
よろしくお願いします。
###発生している問題・エラーメッセージ
popup(v);
のvで赤波線がでる。
赤波線をマウスでかざすと
Cannot resolve symbol 'v'
と出る。
12-26 22:41:45.043 29616-29616/com.test.android.popup E/AndroidRuntime: FATAL EXCEPTION: main Process: com.test.android.popup, PID: 29616 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.android.popup/com.test.android.popup.home}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2260) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2325) at android.app.ActivityThread.access$800(ActivityThread.java:145) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1216) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5266) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:826) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:642) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.nattonz.android.anycalculator.home.onCreate(home.java:61) at android.app.Activity.performCreate(Activity.java:5277) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2213) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2325) at android.app.ActivityThread.access$800(ActivityThread.java:145) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1216) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5266) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:826) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:642) at dalvik.system.NativeStart.main(Native Method)
###該当のソースコード
Java言語
1public class home extends AppCompatActivity{ 2 private PopupWindow mPopupWindow; 3 @Override 4 protected void onCreate(Bundle savedInstanceState) { 5 super.onCreate(savedInstanceState); 6 setContentView(R.layout.activity_home); 7 popup(v); 8 } 9 private void popup(View v){ 10 mPopupWindow = new PopupWindow(home.this); 11 View popupView = getLayoutInflater().inflate(R.layout.popup_layout, null); 12 popupView.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() { 13 @Override 14 public void onClick(View v) { 15 if (mPopupWindow.isShowing()) { 16 mPopupWindow.dismiss(); 17 } 18 } 19 }); 20 mPopupWindow.setContentView(popupView); 21 mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.haikei)); 22 mPopupWindow.setOutsideTouchable(true); 23 mPopupWindow.setFocusable(true); 24 float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 300, getResources().getDisplayMetrics()); 25 mPopupWindow.setWindowLayoutMode((int) width, WindowManager.LayoutParams.WRAP_CONTENT); 26 mPopupWindow.setWidth((int) width); 27 mPopupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); 28 mPopupWindow.showAtLocation(findViewById(R.id.all), Gravity.CENTER, 0, 0); 29 } 30 @Override 31 protected void onDestroy() { 32 if (mPopupWindow != null && mPopupWindow.isShowing()) { 33 mPopupWindow.dismiss(); 34 } 35 super.onDestroy(); 36 } 37}
###試したこと
protected void onCreate(Bundle savedInstanceState) {
を
protected void onCreate(Bundle savedInstanceState, View v) {
に変えてみたりしました。(無意味でした)
###補足情報(言語/FW/ツール等のバージョンなど)
特になし
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。