- 投稿日:2020-07-10T22:43:22+09:00
Android studioに関する質問です。
自作のandroidアプリを作成しているのですが、アプリを起動しても繰り返し停止しています、と表示され、うまく動きませんLogcatを確認したのですが、以下の通り表示されるのですが、よくわかりません。どうやって修正すればいいでしょうか。
2020-07-10 22:39:52.674 17730-17730/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.fumemo, PID: 17730
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.fumemo/com.example.fumemo.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:163)
at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:174)
at android.content.Context.obtainStyledAttributes(Context.java:738)
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:692)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:659)
at androidx.appcompat.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:479)
at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:214)
at com.example.fumemo.MainActivity.(MainActivity.java:35)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:41)
at android.app.Instrumentation.newActivity(Instrumentation.java:1250)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3182)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
- 投稿日:2020-07-10T17:01:24+09:00
Kotlin覚え書き
何の記事?
Kotlinでアプリ開発をしていく中で調べたことを備忘録的にまとめる。
※調べる度に追記します覚え書き
基本文法
when文
val value = 2 when (value) { 0 -> {// valueが0の場合の処理} 1 -> {// valueが1の場合の処理} 2 -> {// valueが2の場合の処理(今回はここに入る)} else -> {// 上記のcase文に入らなかった場合の処理} }for文
for (i in 1..100) println(i) for (i in 1..100) { println(i) }【参考】
https://qiita.com/NagaokaKenichi/items/b68b699dc0b792754d7bLinearLayout
・項目をいい感じに並べたい時に使う
・verticalとhorizontalがある【参考】
https://techacademy.jp/magazine/4455layout_weight
・LinearLayoutで項目を横並びにした時にそれぞれの項目の閉める割合を決定する
【参考】
https://android.keicode.com/basics/ui-layout-weight.phpViewPager2
・ベージをめくるみたいな処理を可能にする
・やること
①ビューを作成する
②フラグメントを作成する
③ViewPager2を追加する
④アクティビティでごにょごにょする
・習うより動かしてみて慣れてみたほうがいい(何事も)
↓
【参考】
https://developer.android.com/training/animation/screen-slide-2?hl=jaAlertDialog
・アプリ内でダイアログを表示する方法
AlertDialog.Builder(this) .setTitle("タイトル") .setMessage("YESかNOを選択してください") .setPositiveButton("YES") { dialog, which -> //Yesを押した時の処理 } .setNegativeButton("NO") { dialog, which -> //Noを押した時の処理 } .show()画面遷移時の値渡し
・intentにputExtraで値を詰め込むことができる
【参考】
https://qiita.com/Takarkiz/items/61f7b1a8fe6a41ae171dTextViewに値を設定する
・普通に.textに設定できる
textView.text = "sample_text"【参考】
https://hirauchi-genta.com/kotlin-textview/RecyclerView
・同じ形式のビューを繰り返し複数表示する
【参考】
https://developer.android.com/guide/topics/ui/layout/recyclerview?hl=ja