Map<String, Object>型の中の Map<String, Object>の要素にアクセスしたいです。
どうすれば、いいでしょうか?
java
1 Map<String, Object> first = new HashMap<String, Object>(); 2 first.put("curve", documentSnapshot.get("part.1.curve")); 3 first.put("length", documentSnapshot.get("part.1.length")); 4 first.put("slope", documentSnapshot.get("part.1.slope")); 5 6 Map<String, Object> second = new HashMap<String, Object>(); 7 second.put("curve", documentSnapshot.get("part.2.curve")); 8 second.put("length", documentSnapshot.get("part.2.length")); 9 second.put("slope", documentSnapshot.get("part.2.slope")); 10 11 Map<String, Object> part = new HashMap<String, Object>(); 12 part.put("1", first); 13 part.put("2", second); 14 Map<String, Object> firebasePartData = new HashMap<String, Object>(); 15 firebasePartData.put("part", part); 16
java
1public void function(Map<String, Object> firebaseCourseData){ 2 3 Object o=firebasePartData.get("first"); 4 int first_curve=(Integer)Integer.parseInt(o.get("curve").toString()); 5 6}
java
1E/AndroidRuntime: FATAL EXCEPTION: main 2 Process: com.example.race_win_android, PID: 13993 3 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference 4 at com.example.race_win_android.Calculate.setResultFirebase(Calculate.java:51) 5 at com.example.race_win_android.MainActivity.calculateToFirebase(MainActivity.java:815) 6 at com.example.race_win_android.MainActivity$6.onSuccess(MainActivity.java:803) 7 at com.example.race_win_android.MainActivity$6.onSuccess(MainActivity.java:725) 8 at com.google.android.gms.tasks.zzn.run(Unknown Source:4) 9 at android.os.Handler.handleCallback(Handler.java:883) 10 at android.os.Handler.dispatchMessage(Handler.java:100) 11 at android.os.Looper.loop(Looper.java:214) 12 at android.app.ActivityThread.main(ActivityThread.java:7356) 13 at java.lang.reflect.Method.invoke(Native Method) 14 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 15 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/09 00:16 編集