gpt4 book ai didi

android - 使用 firebase 出现内存不足错误

转载 作者:行者123 更新时间:2023-11-29 15:45:53 27 4
gpt4 key购买 nike

我在 android 上从 firebase 数据库读取时出现 oom 错误。我正在为选项卡使用 fragment ,这是其中一个选项卡的代码..

public class EventsTab extends Fragment {

ListView listView;
ArrayList<String> titles = new ArrayList<String>();
ArrayList<String> descriptions = new ArrayList<String>();
ArrayList<String> dates = new ArrayList<String>();
ArrayList<String> urls = new ArrayList<String>();
int counter = 0;
float x1,x2;
float y1, y2;

static ProgressDialog dialog;
static AnimationDrawable frameAnimation;
static ProgressBar mProgressBar;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

titles = new ArrayList<String>();
urls = new ArrayList<String>();
dates = new ArrayList<String>();
descriptions = new ArrayList<String>();

View rootView = inflater.inflate(R.layout.activity_events_tab, container, false);
return rootView;

}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

mProgressBar = (ProgressBar) getActivity().findViewById(R.id.my_progress);
mProgressBar.setBackgroundResource(R.drawable.ani_icon);

frameAnimation = (AnimationDrawable) mProgressBar.getBackground();

frameAnimation.start();


Firebase ref = new Firebase("https://dazzling-inferno-7627.firebaseio.com/yourLocal/events/");
ref.addValueEventListener(new ValueEventListener() {

@Override
public void onDataChange(DataSnapshot snapshot) {
System.out.println("There are " + snapshot.getChildrenCount() + " blog posts");


for (DataSnapshot postSnapshot: snapshot.getChildren()) {
Event post = postSnapshot.getValue(Event.class);
titles.add(post.getTitle());
dates.add(post.getDate());
descriptions.add(post.getDescription());

}

listView = (ListView) getActivity().findViewById(R.id.listView3);

CustomList adapter = new CustomList(getActivity(), titles, dates);

listView.setAdapter(adapter);

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

Intent intent = new Intent(getActivity(), ShowEvent.class);
intent.putExtra("title", titles.get(position));
intent.putExtra("date", dates.get(position));
intent.putExtra("description", descriptions.get(position));
startActivity(intent);

}
});
frameAnimation.stop();
mProgressBar.setVisibility(View.INVISIBLE);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});



}

这是错误...

10-27 11:46:36.444: E/AndroidRuntime(11090): FATAL EXCEPTION: main
10-27 11:46:36.444: E/AndroidRuntime(11090): java.lang.OutOfMemoryError
10-27 11:46:36.444: E/AndroidRuntime(11090): at java.lang.AbstractStringBuilder.<init>(AbstractStringBuilder.java:82)
10-27 11:46:36.444: E/AndroidRuntime(11090): at java.lang.StringBuilder.<init>(StringBuilder.java:67)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.shaded.fasterxml.jackson.core.util.TextBuffer.contentsAsString(TextBuffer.java:350)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.shaded.fasterxml.jackson.core.json.ReaderBasedJsonParser.getValueAsString(ReaderBasedJsonParser.java:223)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.shaded.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:29)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.shaded.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:11)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.shaded.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:464)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.shaded.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:98)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.shaded.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:295)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.shaded.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.shaded.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.shaded.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2034)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:181)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.brianmccabe.yournews.EventsTab$Test$1.onDataChange(EventsTab.java:107)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.firebase.client.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:45)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38)
10-27 11:46:36.444: E/AndroidRuntime(11090): at android.os.Handler.handleCallback(Handler.java:615)
10-27 11:46:36.444: E/AndroidRuntime(11090): at android.os.Handler.dispatchMessage(Handler.java:92)
10-27 11:46:36.444: E/AndroidRuntime(11090): at android.os.Looper.loop(Looper.java:137)
10-27 11:46:36.444: E/AndroidRuntime(11090): at android.app.ActivityThread.main(ActivityThread.java:4867)
10-27 11:46:36.444: E/AndroidRuntime(11090): at java.lang.reflect.Method.invokeNative(Native Method)
10-27 11:46:36.444: E/AndroidRuntime(11090): at java.lang.reflect.Method.invoke(Method.java:511)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
10-27 11:46:36.444: E/AndroidRuntime(11090): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
10-27 11:46:36.444: E/AndroidRuntime(11090): at dalvik.system.NativeStart.main(Native Method)

最佳答案

您从 Firebase 下载的数据超出了内存所能容纳的范围。尝试使用 queries 拆分数据, 减少读操作的范围。

关于android - 使用 firebase 出现内存不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33367502/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com