Я получаю эту ошибку в Android Studio, когда пытаюсь запустить свое приложение.Я относительно новичок в Android, и я не могу сделать из этого ни головы, ни хвоста.
06-13 01:45:21.065 3796-3796/com.example.leo.ConnexusHealth W/art: Large object allocation failed: Failed anonymous mmap(0x0, 387129344, 0x3, 0x2, 28, 0): Out of memory. See process maps in the log.
06-13 01:45:21.065 3796-3796/? W/art: Throwing OutOfMemoryError "Failed to allocate a 387125436 byte allocation with 1036624 free bytes and 382MB until OOM"
06-13 01:45:21.071 3796-3796/? I/art: Starting a blocking GC Alloc
06-13 01:45:21.071 3796-3796/? I/art: Starting a blocking GC Alloc
06-13 01:45:21.081 3796-3796/? I/art: Alloc sticky concurrent mark sweep GC freed 3(592B) AllocSpace objects, 0(0B) LOS objects, 44% free, 1255KB/2MB, paused 1.545ms total 9.679ms
06-13 01:45:21.081 3796-3796/? I/art: Starting a blocking GC Alloc
06-13 01:45:21.090 3796-3796/? I/art: Alloc partial concurrent mark sweep GC freed 6(192B) AllocSpace objects, 0(0B) LOS objects, 44% free, 1255KB/2MB, paused 1.636ms total 8.693ms
06-13 01:45:21.091 3796-3796/? I/art: Starting a blocking GC Alloc
06-13 01:45:21.146 3796-3796/? I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 44% free, 1266KB/2MB, paused 904us total 45.367ms
06-13 01:45:21.148 3796-3796/? I/art: Forcing collection of SoftReferences for 369MB allocation
06-13 01:45:21.161 3796-3796/? I/art: Starting a blocking GC Alloc
06-13 01:45:21.195 3796-3796/? I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 44% free, 1255KB/2MB, paused 1.006ms total 29.842ms
06-13 01:45:21.196 3796-3796/? W/art: Disabled moving GC due to the non moving space being full
06-13 01:45:21.251 3796-3806/? I/art: Background sticky concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 370MB/370MB, paused 5.291ms total 35.508ms
06-13 01:45:24.161 3796-3796/? A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 3796 (.ConnexusHealth)
Опять эта ошибка возникает при попытке запустить приложение.Я не могу понять смысл любого другого решения по переполнению стека.Ниже остальная часть моего кода:
Это мой манифест:
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.leoconnelly.connexus">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-feature
android:name="android.hardware.camera.any"
android:required="true" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<application android:allowBackup="true" android:icon="@mipmap/connexus_logo" android:label="@string/app_name" android:roundIcon="@mipmap/connexus_logo_round" android:supportsRtl="true" android:theme="@style/AppTheme" android:hardwareAccelerated="false"
android:largeHeap="true">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HealthCenterListActivity" />
<activity android:name=".HealthCenterSelectedActivity" />
<activity android:name=".MoreInfoActivity" />
<activity android:name=".RecordHealthInfo" />
<activity android:name=".SelectCity"/>
<meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyCvjWU00ZJxl273Idt9h9fLbMJuG-Rfe6w"/>
<meta-data
android:name="android.support.VERSION"
android:value="27.1.1" />
</application>
</manifest>
Далее все мои классы, которые я подозреваю, участвуют:
enter code herepackage com.example.leoconnelly.connexus;
import android.content.Context;
import android.graphics.Typeface;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.InputStream;
import java.util.ArrayList;
/**
* Created by celiachen on 2/5/18.
*/
public class HealthCenterButton {
// instance variables or fields
public String nameOfCenter;
public String neighborhood;
public String imageUrl;
public Double lat;
public Double longi;
public String mini;
// constructor
// default
// method
// static methods that read the json file in and load into Recipe
// static method that loads our healthCenters.json using the helper method
// this method will return an array list of recipes constructed from the JSON
// file
public static ArrayList<HealthCenterButton> getHealthCentersFromFile(String filename, Context context){
ArrayList<HealthCenterButton> healthCenterList = new ArrayList<HealthCenterButton>();
//ArrayList<HealthCenterButton> miniList = new ArrayList<HealthCenterButton>();
// try to read from JSON file
// get information by using the tags
// construct a Recipe Object for each recipe in JSON
// add the object to arraylist
// return arraylist
try{
String jsonString = loadJsonFromAsset("healthCenters.json", context);
JSONObject json = new JSONObject(jsonString);
JSONArray recipes = json.getJSONArray("recipes");
// for loop to go through each recipe in your recipes array
for (int i = 0; i < recipes.length(); i++){
HealthCenterButton recipe = new HealthCenterButton();
recipe.nameOfCenter = recipes.getJSONObject(i).getString("title");
recipe.neighborhood = recipes.getJSONObject(i).getString("url");
recipe.imageUrl = recipes.getJSONObject(i).getString("image");
recipe.lat = recipes.getJSONObject(i).getDouble("lat");
recipe.longi = recipes.getJSONObject(i).getDouble("longi");
recipe.mini = recipes.getJSONObject(i).getString("mini");
// add to arraylist
healthCenterList.add(recipe);
}
/* for (int i = 0; i < recipes.length(); i++){
HealthCenterButton recipe = new HealthCenterButton();
recipe.mini = recipes.getJSONObject(i).getString("mini");
// add to arraylist
miniList.add(recipe);
}
*/
} catch (JSONException e) {
e.printStackTrace();
}
return healthCenterList;
}
// helper method that loads from any Json file
private static String loadJsonFromAsset(String filename, Context context) {
String json = null;
try {
InputStream is = context.getAssets().open(filename);
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
}
catch (java.io.IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}
}
Вот мой следующийкласс:
package com.example.leoconnelly.connexus;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
/**
* Created by celiachen on 2/7/18.
*/
// adapter is needed when you want to do any sort of list or table view
// gets data and decides where to display in the activity
public class HealthCenterButtonAdapter extends BaseAdapter {
// adapter takes the app itself and a list of data to display
private Context mContext;
private ArrayList<HealthCenterButton> mHealthCentersList;
private LayoutInflater mInflater;
public Typeface custom_fontA;
public Typeface custom_fontB;
public Typeface custom_fontC;
public Typeface custom_fontD;
// constructor
public HealthCenterButtonAdapter(Context mContext, ArrayList<HealthCenterButton> mHealthCentersList){
//line of SO
//super(mContext);
mContext.getAssets();
// initialize instances variables
this.mContext = mContext;
this.mHealthCentersList = mHealthCentersList;
mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
custom_fontA = Typeface.createFromAsset(mContext.getAssets(), "fonts/NeuzeitGro.ttf");
custom_fontB = Typeface.createFromAsset(mContext.getAssets(), "fonts/NeuzeitSLTBookHeavy.ttf");
custom_fontC = Typeface.createFromAsset(mContext.getAssets(), "fonts/DINNeuzeitGroteskStd-BdCond.otf");
//custom_fontD = Typeface.createFromAsset(mContext.getAssets(), "fonts/DINNeuzeitGroteskStd-Light.otf");
}
// methods
// a list of methods we need to override
// gives you the number of recipes in the data source
@Override
public int getCount(){
return mHealthCentersList.size();
}
// returns the item at specific position in the data source
@Override
public Object getItem(int position){
return mHealthCentersList.get(position);
}
// returns the row id associated with the specific position in the list
@Override
public long getItemId(int position){
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder;
// check if the view already exists
// if yes, you don't need to inflate and findViewbyID again
if (convertView == null){
// inflate
convertView = mInflater.inflate(R.layout.find_care_health_centers_list, parent, false);
// add the views to the holder
holder = new ViewHolder();
// views
holder.nameOfCenterTextView = convertView.findViewById(R.id.health_center_list_title);
holder.neighborhoodTextView = convertView.findViewById(R.id.neighborhood);
holder.thumbnailImageView = convertView.findViewById(R.id.health_center_list_image);
// add the holder to the view
// for future use
convertView.setTag(holder);
}
else{
// get the view holder from converview
holder = (ViewHolder)convertView.getTag();
}
//set custom fonts
//end
// get relavate subview of the row view
TextView nameOfCenterTextView = holder.nameOfCenterTextView;
TextView neighborhoodTextView = holder.neighborhoodTextView;
ImageView thumbnailImageView = holder.thumbnailImageView;
// get corresonpinding recipe for each row
HealthCenterButton healthCenterButton = (HealthCenterButton)getItem(position);
// update the row view's textviews and imageview to display the information
// titleTextView
nameOfCenterTextView.setText(healthCenterButton.nameOfCenter);
nameOfCenterTextView.setTextColor(ContextCompat.getColor(mContext, R.color.colorAccent));
nameOfCenterTextView.setTextSize(18);
nameOfCenterTextView.setTypeface(custom_fontB);
// servingTextView
neighborhoodTextView.setText(healthCenterButton.neighborhood);
neighborhoodTextView.setTextSize(14);
neighborhoodTextView.setTextColor(ContextCompat.getColor(mContext, R.color.colorPrimaryDark));
neighborhoodTextView.setTypeface(custom_fontA);
// imageView
// use Picasso library to load image from the image url
Picasso.with(mContext).load(healthCenterButton.imageUrl).into(thumbnailImageView);
return convertView;
}
// viewHolder
// is used to customize what you want to put into the view
// it depends on the layout design of your row
// this will be a private static class you have to define
private static class ViewHolder{
public TextView nameOfCenterTextView;
public TextView neighborhoodTextView;
public ImageView thumbnailImageView;
}
// intent is used to pass information between activities
// intent -> pacakge
// sender, receiver
}
package com.example.leoconnelly.connexus;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import java.util.ArrayList;
/**
* Created by leoconnelly on 4/9/18.
*/
public class HealthCenterListActivity extends AppCompatActivity {
private ListView mListView ;
public Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hospitals_list_view);
final ArrayList<HealthCenterButton> healthCentersList = HealthCenterButton.getHealthCentersFromFile("healthCenters.json", this);
if (healthCentersList.size()==2) {
System.out.println("YES YES YES YES");
}
mContext = this;
// String x = healthCentersList.get(2).toString();
// System.out.println(x);
HealthCenterButtonAdapter adapter = new HealthCenterButtonAdapter(this, healthCentersList);
//set the views
mListView = findViewById(R.id.hospitals_list_view);
mListView.setAdapter(adapter);
//set up the positions for the next screen
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id){
HealthCenterButton SelectedHealthCareCenter = healthCentersList.get(position);
Intent detailIntent = new Intent(mContext, HealthCenterSelectedActivity.class);
detailIntent.putExtra("latitude", SelectedHealthCareCenter.lat);
detailIntent.putExtra("longitude", SelectedHealthCareCenter.longi);
detailIntent.putExtra("nameOfCenter", SelectedHealthCareCenter.nameOfCenter);
detailIntent.putExtra("neighborhood", SelectedHealthCareCenter.neighborhood);
detailIntent.putExtra("imageUrl", SelectedHealthCareCenter.imageUrl);
detailIntent.putExtra("miniUrl", SelectedHealthCareCenter.imageUrl);
startActivity(detailIntent);
}
});
//get arraylists
//get adapter
}
}