草庐IT

android - Recycler View 中的 OutOfMemory 错误

coder 2023-12-27 原文

我正在制作一个简单的应用程序,它有一个带有交错布局的 recyclerview 在 PHP 脚本的帮助下使用 Volley 库从服务器加载数据 当我单击 RecyclerView 中的项目时,我的应用程序崩溃并显示以下错误日志。

此外,当我查看内存日志时,应用程序正在使用大量内存来将数据从服务器加载到 recyclerView

Log//应用启动

I/Choreographer: Skipped 189 frames!  The application may be doing too much work on its main thread.
I/art: Background partial concurrent mark sweep GC freed 3797(174KB) AllocSpace objects, 1(36KB) LOS objects, 6% free, 56MB/60MB, paused 19.976ms total 90.718ms

错误日志//点击RecyclerView中的item之后

I/art: Alloc sticky concurrent mark sweep GC freed 10628(425KB) AllocSpace objects, 5(562KB) LOS objects, 2% free, 59MB/60MB, paused 476us total 7.071ms
I/art: Alloc partial concurrent mark sweep GC freed 928(67KB) AllocSpace objects, 1(16KB) LOS objects, 6% free, 58MB/62MB, paused 647us total 37.510ms
I/art: Alloc concurrent mark sweep GC freed 241(23KB) AllocSpace objects, 0(0B) LOS objects, 6% free, 58MB/62MB, paused 574us total 49.041ms
I/art: Forcing collection of SoftReferences for 21MB allocation
I/art: Alloc concurrent mark sweep GC freed 13(472B) AllocSpace objects, 0(0B) LOS objects, 6% free, 58MB/62MB, paused 429us total 16.959ms
E/art: Throwing OutOfMemoryError "Failed to allocate a 22400012 byte allocation with 4194304 free bytes and 5MB until OOM"I/art: Alloc sticky concurrent mark sweep GC freed 5(608B) AllocSpace objects, 0(0B) LOS objects, 3% free, 58MB/60MB, paused 509us total 8.143ms
I/art: Alloc partial concurrent mark sweep GC freed 17(480B) AllocSpace objects, 0(0B) LOS objects, 6% free, 58MB/62MB, paused 5.517ms total 17.409ms
I/art: Alloc concurrent mark sweep GC freed 14(448B) AllocSpace objects, 0(0B) LOS objects, 6% free, 58MB/62MB, paused 1.077ms total 107.298ms
I/art: Forcing collection of SoftReferences for 21MB allocation
I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 6% free, 58MB/62MB, paused 620us total 36.488ms
E/art: Throwing OutOfMemoryError "Failed to allocate a 22400012 byte allocation with 4194304 free bytes and 5MB until OOM"
D/skia: --- allocation failed for scaled bitmap
D/AndroidRuntime: Shutting down VM
FATAL EXCEPTION: main
Process: com.trueblueoperator.swachhapp, PID: 25499
  java.lang.OutOfMemoryError: Failed to allocate a 22400012 byte allocation with 4194304 free bytes and 5MB until OOM
  at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988)
  at android.content.res.Resources.loadDrawableForCookie(Resources.java:2474)
  at android.content.res.Resources.loadDrawable(Resources.java:2381)
  at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
  at android.widget.ImageView.<init>(ImageView.java:146)
  at android.widget.ImageView.<init>(ImageView.java:135)
  at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:58)
  at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:54)
  at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:95)
  at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:938)
  at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:992)
  at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
  at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
  at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
  at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
  at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
  at com.trueblueoperator.swachhapp.StoryDetailFragment.onCreate(StoryDetailFragment.java:45)
  at android.app.Activity.performCreate(Activity.java:5990)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
  at android.app.ActivityThread.access$800(ActivityThread.java:151)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:135)
  at android.app.ActivityThread.main(ActivityThread.java:5254)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

这是我的包含 Recycler View 的 Fragment 类的代码

FragmetnAllStory.java 文件

public class FragmentAllStory extends Fragment implements SwipeRefreshLayout.OnRefreshListener{// implements RecyclerView.OnScrollChangeListener {

//Creating a List of superheroes
private List<AllStoryData> allStoryDataList;

//Volley Request Queue
private RequestQueue requestQueue;

private ProgressBar progressBar;
//The request counter to send ?page=1, ?page=2  requests
private int requestCount = 1;
private RecyclerView recyclerView;
private SwipeRefreshLayout swipeRefreshLayout;
private RecyclerView.Adapter adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);

}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    requestCount = 1;
    View v = inflater.inflate(R.layout.fragment_all_story, container, false);
    progressBar = (ProgressBar) v.findViewById(R.id.progress_bar);

    swipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setOnRefreshListener(this);
    recyclerView = (RecyclerView) v.findViewById(R.id.recycler_view2);//new RecyclerView(getActivity());
    if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, 1));
    }
    else {
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, 1));
    }
    allStoryDataList = new ArrayList<>();
    requestQueue = Volley.newRequestQueue(getContext());
    //getData();
    recyclerView.addOnScrollListener(new OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);

            if(isLastItemDisplaying(recyclerView))
            {
                getData();
            }

        }
    });
    adapter = new AllStoryAdapter(allStoryDataList, getActivity());
    recyclerView.setAdapter(adapter);


    return v;
}

//Request to get json from server we are passing an integer here
//This integer will used to specify the page number for the request ?page = requestcount
//This method would return a JsonArrayRequest that will be added to the request queue
    private JsonArrayRequest getDataFromServer(int requestCount) {

    //Displaying Progressbar
    progressBar.setVisibility(View.VISIBLE);


    //JsonArrayRequest of volley
    JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Config.DATA_URL + String.valueOf(requestCount),
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    //Calling method parseData to parse the json response
                    parseData(response);
                    //Hiding the progressbar
                    progressBar.setVisibility(View.GONE);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    progressBar.setVisibility(View.GONE);
                    //If an error occurs that means end of the list has reached
                    Toast.makeText(getContext(), "No More Items Available", Toast.LENGTH_SHORT).show();
                }
            });

    //Returning the request
    return jsonArrayRequest;
}

@Override
public void onResume() {
    super.onResume();
    requestCount =1;
    allStoryDataList.clear();
    getData();
}

//This method will get data from the web api
private void getData() {
    //Adding the method to the queue by calling the method getDataFromServer
    requestQueue.add(getDataFromServer(requestCount));
    //Incrementing the request counter
    requestCount++;
    swipeRefreshLayout.setRefreshing(false);
}

//This method will parse json data
private void parseData(JSONArray array) {
    for (int i = 0; i < array.length(); i++) {
        //Creating the superhero object
        AllStoryData allStoryData = new AllStoryData();
        JSONObject json = null;
        try {
            //Getting json
            json = array.getJSONObject(i);

            //Adding data to the superhero object
            allStoryData.setImageUrl(json.getString(Config.TAG_IMAGE_URL));
            allStoryData.setName(json.getString(Config.TAG_NAME));
            allStoryData.setPublisher(json.getString(Config.TAG_PUBLISHER));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        //Adding the superhero object to the list
        allStoryDataList.add(allStoryData);
        Log.d("ListSuper", "" + allStoryDataList);
    }

    //Notifying the adapter that data has been added or changed
    adapter.notifyDataSetChanged();
}

//This method would check that the recyclerview scroll has reached the bottom or not
private boolean isLastItemDisplaying(RecyclerView recyclerView) {
    int[] info = new int[3];
    if (recyclerView.getAdapter().getItemCount() != 0) {
        ((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).findLastCompletelyVisibleItemPositions(info);
        Log.d("info", "" + info[0] + " " + info[1]);
        if (info[0] == recyclerView.getAdapter().getItemCount() - 1 || info[1] == recyclerView.getAdapter().getItemCount() - 1 || info[2] == recyclerView.getAdapter().getItemCount() - 1)
            return true;
    }
    return false;
}

@Override
public void onRefresh() {
 requestCount =1;
    allStoryDataList.clear();
    getData();
}
}

StoryDe​​tailFragment.java 文件

public class StoryDetailFragment extends AppCompatActivity implements View.OnClickListener, AppBarLayout.OnOffsetChangedListener {

TextView textView;
TextView like;
ImageView imageView;
String requestString;
RequestParams params = new RequestParams();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_story_detail); // error line 45

    // Intent Message sent from Broadcast Receiver
    requestString = getIntent().getStringExtra("Heading");

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    imageView = (ImageView) findViewById(R.id.story_image);
    like = (TextView) findViewById(R.id.likes);
    if (requestString != null) {
        textView = (TextView) findViewById(R.id.story_detail_message);
        textView.setText(requestString);
    }

    AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
    appBarLayout.addOnOffsetChangedListener(this);
    FloatingActionButton fab1 = (FloatingActionButton) findViewById(R.id.fab1);
    FloatingActionButton fab2 = (FloatingActionButton) findViewById(R.id.fab2);
    fab1.setOnClickListener(this);
    fab2.setOnClickListener(this);

    getData();


}


private void getData() {

    params.put("heading", "" + requestString);
    // Make RESTful webservice call using AsyncHttpClient object
    AsyncHttpClient client = new AsyncHttpClient();

    client.get(Config.DETAIL_URL, params,
            new JsonHttpResponseHandler() {

                // When the response returned by REST has Http
                // response code '200'

                @Override
                public void onSuccess(JSONArray response) {

                    Log.d("result",""+response);
                    try {
                        JSONObject result = response.getJSONObject(0);
                        textView.setText((CharSequence) result.get("detailstory"));
                        like.setText((CharSequence) result.get("likes"));
                        String res = (String) result.get("images");
                        //URL url = new URL(res);
                        //Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                        new DownloadImagesTask().execute(res);


                        Log.d("result",""+res);

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    //super.onSuccess(response);
                }


                // When the response returned by REST has Http
                // response code other than '200' such as '404',
                // '500' or '403' etc


                @Override
                public void onFailure(int statusCode, Throwable error, JSONArray errorResponse) {
                    // When Http response code is '404'
                    if (statusCode == 404) {
                        Toast.makeText(StoryDetailFragment.this,
                                "Requested resource not found",
                                Toast.LENGTH_LONG).show();
                    }
                    // When Http response code is '500'
                    else if (statusCode == 500) {
                        Toast.makeText(StoryDetailFragment.this,
                                "Something went wrong at server end",
                                Toast.LENGTH_LONG).show();
                    }
                    // When Http response code other than 404, 500
                    else {
                        Toast.makeText(
                                StoryDetailFragment.this,
                                "Unexpected Error occcured! [Most common Error: Device might "
                                        + "not be connected to Internet or remote server is not up and running], check for other errors as well",
                                Toast.LENGTH_LONG).show();
                    }
                }

            });
}

@Override
public void onBackPressed() {
    super.onBackPressed();
    finish();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == android.R.id.home) {
        onBackPressed();
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.fab1:
            // Code for button like click

            break;

        case R.id.fab2:
            // Code for saving the articles


            break;
    }
}

@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    if (Math.abs(verticalOffset) <= appBarLayout.getTotalScrollRange() - 120) {
        like.setVisibility(TextView.VISIBLE);
    } else {
        like.setVisibility(TextView.GONE);
    }
}

public class DownloadImagesTask extends AsyncTask<String, Void, Bitmap> {

    @Override
    protected Bitmap doInBackground(String... params) {
        return download_Image(params[0]);
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        imageView.setImageBitmap(result);
    }

    private Bitmap download_Image(String url) {

        Bitmap bmp = null;
        try {
            URL ulrn = new URL(url);
            HttpURLConnection con = (HttpURLConnection) ulrn.openConnection();
            InputStream is = con.getInputStream();
            bmp = BitmapFactory.decodeStream(is);
            if (null != bmp)
                return bmp;

        } catch (Exception e) {
        }
        return bmp;
    }
}
}

XML 文件 fragment_story_detail.xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.trueblueoperator.samplescrolling.ScrollingActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="192dp"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/story_image"
            android:layout_width="match_parent"
            android:layout_height="192dp"
            android:scaleType="centerCrop"
            android:src="@drawable/image"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_scrolling"/>

<TextView
    android:id="@+id/likes"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="5dp"
    android:paddingBottom="5dp"
    android:paddingTop="5dp"
    android:paddingRight="70dp"
    android:layout_marginRight="10dp"
    android:textSize="20dp"
    android:background="@drawable/rounded_corner"
    android:text="100"
    app:layout_anchor="@id/app_bar"
    app:layout_anchorGravity="right|bottom"
    />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/like"
    app:layout_anchor="@id/app_bar"
    app:layout_anchorGravity="right|bottom" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/like"
    android:layout_gravity="bottom|right" />

</android.support.design.widget.CoordinatorLayout>

最佳答案

你的 logcat 抛出什么

E/art: Throwing OutOfMemoryError "Failed to allocate a 22400012 byte allocation with 4194304 free bytes and 5MB until OOM"I/art: Alloc 14(448B) AllocSpace objects, 0(0B) LOS objects, 6% free, 58MB/62MB, paused 1.077ms total 107.298ms I/art: Forcing collection of SoftReferences for 21MB allocation I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 6% free, 58MB/62MB, paused 620us total 36.488ms E/art: Throwing OutOfMemoryError "Failed to allocate a 22400012 byte allocation with 4194304 free bytes and 5MB until OOM" D/skia: --- allocation failed for scaled bitmap

当应用程序试图向堆空间区域添加更多数据但没有足够的空间时,将触发 Java 堆空间错误。

请减小图像大小并增加 VM 堆大小 (AVD)

每个 Android 设备都有不同数量的 RAM 可供系统使用,因此为每个应用提供不同的堆限制。您可以调用 getMemoryClass() 来估计您的应用的可用堆(以兆字节为单位)。如果您的应用试图分配比此处可用内存更多的内存,它将收到一个OutOfMemoryError

建议

使用 android:largeHeap="true" 不是一个好主意。

请仔细阅读

  1. Managing Your App's Memory

  2. Strange out of memory issue while loading an image to a Bitmap object

关于android - Recycler View 中的 OutOfMemory 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35030184/

有关android - Recycler View 中的 OutOfMemory 错误的更多相关文章

  1. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  2. ruby - 其他文件中的 Rake 任务 - 2

    我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时

  3. ruby-on-rails - Ruby net/ldap 模块中的内存泄漏 - 2

    作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代

  4. ruby-on-rails - Rails 3 中的多个路由文件 - 2

    Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题

  5. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  6. ruby-on-rails - Rails - 一个 View 中的多个模型 - 2

    我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何

  7. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

  8. ruby-on-rails - Rails 应用程序中的 Rails : How are you using application_controller. rb 是新手吗? - 2

    刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr

  9. ruby-on-rails - form_for 中不在模型中的自定义字段 - 2

    我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢

  10. ruby - rspec 需要 .rspec 文件中的 spec_helper - 2

    我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只

随机推荐