如何解决奇怪的 rList 输出文件 Android Studio
我目前正在 Android Studio 上构建情绪跟踪器和日记组合应用程序,但我遇到了这个特殊问题。每次我打开应用程序时,都会直接在应用程序的文件中弹出这个 rList 文件(这是我保存所有文本日记条目的地方) 这是我单击它时显示的内容:�� sr java.util.ArrayListx����a� I sizexp w t 2131165276x
我还没有看到过这样的问题。我只在饼图中使用数组列表,但我不知道为什么会出现这些数字和符号。另外我不知道为什么它被存储在fliesDir 唉,这是我的饼图代码:
private void addDataSet() {
Log.d(TAG,"addDataSet started");
ArrayList<PieEntry> yEntrys = new ArrayList<>();
ArrayList<String> xEntrys = new ArrayList<>();
for(int i = 0; i < yData.length; i++){
yEntrys.add(new PieEntry(yData[i],i));
}
for(int i = 1; i < xData.length; i++){
xEntrys.add((xData[i]));
}
// create data set
PieDataSet pieDataSet = new PieDataSet(yEntrys,"Elated");
pieDataSet.setSliceSpace(2);
pieDataSet.setValueTextSize(14);
//add colors
ArrayList<Integer> colors = new ArrayList<>();
colors.add(Color.rgb(239,8,192));
colors.add(Color.rgb(4,208,79));
colors.add(Color.rgb(188,111,9));
colors.add(Color.rgb(51,127,242));
colors.add(Color.rgb(251,17));
pieDataSet.setColors(colors);
// add legend
Legend legend = pieChart.getLegend();
legend.setForm(Legend.LegendForm.CIRCLE);
// create pie data object
PieData pieData = new PieData(pieDataSet);
pieChart.setData(pieData);
pieChart.setUsePercentValues(true);
pieChart.invalidate();
}
其次是保存文本日记条目的代码:
public void save(View v) {
textPath = getApplication().getFilesDir().getAbsolutePath();
SimpleDateFormat formatter = new SimpleDateFormat("MM_dd_yy",Locale.US);
Date Now = new Date();
textFile = inputTitle.getText().toString();
String text = inputFeelings.getText().toString();
FileOutputStream fos = null;
try {
fos = openFileOutput(textFile,MODE_PRIVATE);
fos.write(text.getBytes());
inputFeelings.getText().clear();
Toast.makeText(this,"Saved to " + getFilesDir() + "/" + textFile,Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
e.printstacktrace();
} catch (IOException e) {
e.printstacktrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printstacktrace();
}
}
}
}
我还在 viewPagerAdapter 中使用了 Arraylists,我认为这是导致此问题的实际原因,代码如下:
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
private List<Fragment> fragmentList = new ArrayList<>();
private List<String> stringList = new ArrayList<>();
public ViewPagerAdapter(@NonNull FragmentManager fm) {
super(fm);
}
@NonNull
@Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
@Override
public int getCount() {
return fragmentList.size();
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return stringList.get(position);
}
public void addFragment(Fragment fragment,String title){
fragmentList.add(fragment);
stringList.add(title);
}
}
感谢任何形式的帮助。提前致谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。