質問編集履歴
2
コード、エラーメッセージの詳細を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,81 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
エミュレータを立ち上げて確認しようとしていますが、
|
13
|
+
開発中のアプリをエミュレータを立ち上げて確認しようとしていますが、以下のエラーによりアプリが落ちてしまい困っています。。
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
```
|
18
|
+
|
19
|
+
2020-04-09 18:32:37.189 23279-23279/com.example.abb E/AndroidRuntime: FATAL EXCEPTION: main
|
20
|
+
|
21
|
+
Process: com.example.abb, PID: 23279
|
22
|
+
|
23
|
+
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.abb/com.example.abb.MainActivity}: java.lang.IllegalStateException: Method call should not happen from the main thread.
|
24
|
+
|
25
|
+
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3333)
|
26
|
+
|
27
|
+
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3477)
|
28
|
+
|
29
|
+
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
|
30
|
+
|
31
|
+
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
|
32
|
+
|
33
|
+
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
|
34
|
+
|
35
|
+
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2043)
|
36
|
+
|
37
|
+
at android.os.Handler.dispatchMessage(Handler.java:106)
|
38
|
+
|
39
|
+
at android.os.Looper.loop(Looper.java:216)
|
40
|
+
|
41
|
+
at android.app.ActivityThread.main(ActivityThread.java:7464)
|
42
|
+
|
43
|
+
at java.lang.reflect.Method.invoke(Native Method)
|
44
|
+
|
45
|
+
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
|
46
|
+
|
47
|
+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:955)
|
48
|
+
|
49
|
+
Caused by: java.lang.IllegalStateException: Method call should not happen from the main thread.
|
50
|
+
|
51
|
+
at com.squareup.picasso.Utils.checkNotMain(Utils.java:121)
|
52
|
+
|
53
|
+
at com.squareup.picasso.RequestCreator.get(RequestCreator.java:416)
|
54
|
+
|
55
|
+
at com.example.abb.MainActivity.onCreate(MainActivity.kt:28)
|
56
|
+
|
57
|
+
at android.app.Activity.performCreate(Activity.java:7990)
|
58
|
+
|
59
|
+
at android.app.Activity.performCreate(Activity.java:7979)
|
60
|
+
|
61
|
+
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
|
62
|
+
|
63
|
+
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3308)
|
64
|
+
|
65
|
+
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3477)
|
66
|
+
|
67
|
+
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
|
68
|
+
|
69
|
+
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
|
70
|
+
|
71
|
+
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
|
72
|
+
|
73
|
+
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2043)
|
74
|
+
|
75
|
+
at android.os.Handler.dispatchMessage(Handler.java:106)
|
76
|
+
|
77
|
+
at android.os.Looper.loop(Looper.java:216)
|
78
|
+
|
79
|
+
at android.app.ActivityThread.main(ActivityThread.java:7464)
|
80
|
+
|
81
|
+
at java.lang.reflect.Method.invoke(Native Method)
|
82
|
+
|
83
|
+
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
|
84
|
+
|
85
|
+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:955)
|
86
|
+
|
87
|
+
```
|
14
88
|
|
15
89
|
|
16
90
|
|
@@ -20,19 +94,59 @@
|
|
20
94
|
|
21
95
|
```kotlin
|
22
96
|
|
23
|
-
|
97
|
+
class MainActivity : AppCompatActivity() {
|
24
|
-
|
25
|
-
var drawable = BitmapDrawable(resources, bitmap)
|
26
98
|
|
27
99
|
|
28
100
|
|
29
|
-
|
101
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
30
102
|
|
31
|
-
|
103
|
+
super.onCreate(savedInstanceState)
|
32
104
|
|
33
|
-
|
105
|
+
setContentView(R.layout.activity_main)
|
34
106
|
|
107
|
+
|
108
|
+
|
109
|
+
var url = "http://i.imgur.com/DvpvklR.png"
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
var bitmap: Bitmap = Picasso.get().load(url).get()
|
114
|
+
|
115
|
+
var drawable = BitmapDrawable(resources, bitmap)
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
val navView: BottomNavigationView = findViewById(R.id.nav_view)
|
120
|
+
|
121
|
+
var a: Menu = navView.menu
|
122
|
+
|
123
|
+
val b: MenuItem = a.findItem(R.id.navigation_home)
|
124
|
+
|
125
|
+
|
126
|
+
|
35
|
-
|
127
|
+
b.setIcon(drawable)
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
val navController = findNavController(R.id.nav_host_fragment)
|
132
|
+
|
133
|
+
// Passing each menu ID as a set of Ids because each
|
134
|
+
|
135
|
+
// menu should be considered as top level destinations.
|
136
|
+
|
137
|
+
val appBarConfiguration = AppBarConfiguration(setOf(
|
138
|
+
|
139
|
+
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications))
|
140
|
+
|
141
|
+
setupActionBarWithNavController(navController, appBarConfiguration)
|
142
|
+
|
143
|
+
navView.setupWithNavController(navController)
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
}
|
36
150
|
|
37
151
|
```
|
38
152
|
|
@@ -42,7 +156,7 @@
|
|
42
156
|
|
43
157
|
|
44
158
|
|
45
|
-
非同期制御が必要なのかと思い、runBlockingを使って試してみてましたがエ
|
159
|
+
非同期制御が必要なのかと思い、runBlockingを使って試してみてましたが非同期処理の基礎を理解できていなくエラーが解消できずです。
|
46
160
|
|
47
161
|
|
48
162
|
|
1
ソースコードを修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -21,6 +21,10 @@
|
|
21
21
|
```kotlin
|
22
22
|
|
23
23
|
var bitmap: Bitmap = Picasso.get().load(url).get()
|
24
|
+
|
25
|
+
var drawable = BitmapDrawable(resources, bitmap)
|
26
|
+
|
27
|
+
|
24
28
|
|
25
29
|
val navView: BottomNavigationView = findViewById(R.id.nav_view)
|
26
30
|
|