Android - 无法实例化类型[simple type,class]

时间:2017-07-11 17:07:23

标签: android firebase

当我尝试打开活动时,我遇到了导致我的应用崩溃的问题。这是引起问题的行:Person person = postSnapshot.getValue(Person.class);.我尝试过其他解决方案,例如删除postSnapshot但它还没有工作。这段代码在其他两项活动中运作良好,所以我完全失去了为什么它现在不能正常工作。

错误:

E/UncaughtException: com.firebase.client.FirebaseException: Failed to bounce to type
                                                        at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:185)
                                                        at uk.co.jaunt_app.jaunt.PlanTripActivity$7.onDataChange(PlanTripActivity.java:264)
                                                        at com.firebase.client.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:45)
                                                        at com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45)
                                                        at com.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38)
                                                        at android.os.Handler.handleCallback(Handler.java:751)
                                                        at android.os.Handler.dispatchMessage(Handler.java:95)
                                                        at android.os.Looper.loop(Looper.java:154)
                                                        at android.app.ActivityThread.main(ActivityThread.java:6776)
                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
                                                     Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class uk.co.jaunt_app.jaunt.Person] from String value; no single-String constructor/factory method

守则:

planRef.addValueEventListener(new ValueEventListener() {
            @Nullable
            @Override
            public void onDataChange (DataSnapshot snapshot) {
                for (final DataSnapshot postSnapshot : snapshot.getChildren()) {
                    //Getting the data from snapshot

                    Person person = postSnapshot.getValue(Person.class);
                    final String planName = person.getPlanName();
                    final String planLat = person.getPlanLat();
                    final String planLong = person.getPlanLong();

                    adapter.notifyDataSetChanged();

                    feedPop.add(
                            new planPinsFeed(planName, planLat, planLong));

                    final ArrayAdapter<planPinsFeed> adapter = new feed2ArrayAdapter(PlanTripActivity.this, 0, feedPop);

                    ListView listView = (ListView) findViewById(R.id.customListView2);
                    listView.setAdapter(adapter);

                    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view,
                                                int position, long id) {

                            String newPlanLocName = feedPop.get(position).getFeedPlanLocName().toString();
                            String newPlanLocLat = feedPop.get(position).getFeedPlanLat().toString();
                            String newPlanLocLong = feedPop.get(position).getFeedPlanLong().toString();

                            double plannewlat = Double.valueOf(newPlanLocLat);
                            double plannewlong = Double.valueOf(newPlanLocLong);

                            LatLng New = new LatLng(plannewlat, plannewlong);
                            mMap.addMarker(new MarkerOptions().position(New).title(newPlanLocName).draggable(true)
                                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.mappin)));
                            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(New, 14 ));
                        }
                    });

                }
            }

0 个答案:

没有答案