【问题标题】:NoSuchMethodException - PerfIOPrefetchStartNoSuchMethodException - PerfIOPrefetchStart
【发布时间】:2018-02-28 13:21:01
【问题描述】:

我的 RecyclerViews 没有显示在这个活动中,所以我在手机上运行应用程序时查看了 LogCat,只是发现了这个错误:你们中有人知道它来自哪里吗?似乎(根据此处的其他帖子)它可以链接到 Context()SharedPreferences 但我看不出它们的使用会出错:

活动

package com.olirwin.spartacus.deutsch;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;

public class players extends AppCompatActivity {

ArrayList<String> playerNames;
Button send;
PlayerAdapter Adapter;
RecyclerView playerList;
String[] names;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_players);

    playerNames = new ArrayList<String>();

    final ArrayList<Player> players = new ArrayList<Player>();
    send = findViewById(R.id.b_send);



    Bundle extra = new Bundle();
    final int numPlayers = extra.getInt("numPlayers");
    System.out.println(numPlayers);
    for (int i = 0; i < numPlayers; i++)
    {
        playerNames.add("Joueur " + (i+1) + " : ");
    }
    playerList = findViewById(R.id.player_list);
    playerList.setLayoutManager(new LinearLayoutManager(this));
    Adapter = new PlayerAdapter(playerNames,this);
    playerList.setAdapter(Adapter);
    names = new String[numPlayers];



    Adapter.notifyDataSetChanged();

    send.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            for (int i = 0; i < numPlayers; i++) {
                players.add(new Player(names[i]));
            }

            Intent intent = new Intent(view.getContext(), Score.class);
            intent.putExtra("players", players);
            view.getContext().startActivity(intent);
        }
    });

}



private class PlayerAdapter extends
        RecyclerView.Adapter<PlayerAdapter.PlayerHolder> {
    private ArrayList<String> playerNames;
    private Context context;

    public PlayerAdapter (ArrayList<String> playerNames, Context context) {
        this.playerNames = playerNames;
        this.context = context;
    }

    @Override
    public PlayerHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v =

LayoutInflater.from(players.this).inflate(R.layout.list_cell, parent,
                        false);
        return new PlayerHolder(v);
    }


    @Override
    public void onBindViewHolder(PlayerHolder holder, final int position) {
        holder.bind(this.playerNames.get(position));

        holder.mPlayerName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int
                    start, int before,
                                          int count) {
                names[position] = charSequence.toString();
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int start,
                                      int before,
                                      int count){

            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });



    }

    @Override
    public int getItemCount() {
        return playerNames.size();
    }



    public class PlayerHolder extends RecyclerView.ViewHolder {

        TextView mPlayerLabel;
        EditText mPlayerName;


        public PlayerHolder(View itemView) {
            super(itemView);
            mPlayerLabel = itemView.findViewById(R.id.player_label);
            mPlayerName = itemView.findViewById(R.id.player_name);
        }

        public void bind(String playerName) {
            mPlayerLabel.setText(playerName);
            mPlayerName.setHint("Nom de " + playerName);
        }

        public String getData(){
            return mPlayerName.getText().toString();
        }

    }
}
}

LogCat

02-28 14:13:46.476 17413-17413/? I/zygote64: Late-enabling -Xcheck:jni
02-28 14:13:46.514 17413-17449/? E/zygote64: Failed sending reply to             debugger: Broken pipe
02-28 14:13:46.515 17413-17449/? I/zygote64: Debugger is no longer active
02-28 14:13:46.597 17413-17413/? D/Embryo: preload     com.olirwin.spartacus.deutsch, 30ms, hwui=true, layout=false, decor=false
02-28 14:13:46.604 17413-17467/? I/Adreno: QUALCOMM build                   : 076f837, I801ffd6741
                                       Build Date                       :     10/24/17
                                       OpenGL ES Shader Compiler Version:     EV031.20.00.04
                                       Local Branch                     : 
                                       Remote Branch                    : 
                                       Remote Branch                    : 
                                       Reconstruct Branch               : 
02-28 14:13:46.604 17413-17467/? I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/hw/gralloc.msm8998.so from the current namespace instead.
02-28 14:13:46.601 17413-17413/? W/RenderThread: type=1400 audit(0.0:141319): avc: denied { search } for name="proc" dev="debugfs" ino=16971 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:qti_debugfs:s0 tclass=dir permissive=0
02-28 14:13:46.609 17413-17467/? I/Adreno: PFP: 0x005ff087, ME: 0x005ff063
02-28 14:13:46.615 17413-17467/? I/OpenGLRenderer: Initialized EGL, version 1.4
02-28 14:13:46.615 17413-17467/? D/OpenGLRenderer: HWUI GL Pipeline
02-28 14:13:46.615 17413-17467/? D/OpenGLRenderer: Swap behavior 2
02-28 14:13:46.817 17413-17413/? E/BoostFramework: BoostFramework() : Exception_1 = java.lang.NoSuchMethodException: perfIOPrefetchStart [int, class java.lang.String]
02-28 14:13:46.817 17413-17413/? E/BoostFramework: BoostFramework() : Exception_1 = java.lang.NoSuchMethodException: perfIOPrefetchStart [int, class java.lang.String]
02-28 14:13:46.914 17413-17413/? D/AppTracker: App Event: start
02-28 14:13:47.012 17413-17467/? I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/hw/gralloc.msm8998.so from the current namespace instead.
02-28 14:13:49.884 17413-17413/com.olirwin.spartacus.deutsch D/AppTracker: App Event: stop
02-28 14:13:49.906 17413-17413/com.olirwin.spartacus.deutsch E/BoostFramework: BoostFramework() : Exception_1 = java.lang.NoSuchMethodException: perfIOPrefetchStart [int, class java.lang.String]
02-28 14:13:49.906 17413-17413/com.olirwin.spartacus.deutsch E/BoostFramework: BoostFramework() : Exception_1 = java.lang.NoSuchMethodException: perfIOPrefetchStart [int, class java.lang.String]
02-28 14:13:49.909 17413-17447/com.olirwin.spartacus.deutsch I/zygote64: Do partial code cache collection, code=30KB, data=25KB
02-28 14:13:49.909 17413-17447/com.olirwin.spartacus.deutsch I/zygote64: After     code cache collection, code=30KB, data=25KB
02-28 14:13:49.909 17413-17447/com.olirwin.spartacus.deutsch I/zygote64: Increasing code cache capacity to 128KB
02-28 14:13:49.917 17413-17413/com.olirwin.spartacus.deutsch E/BoostFramework: BoostFramework() : Exception_1 = java.lang.NoSuchMethodException: perfIOPrefetchStart [int, class java.lang.String]
02-28 14:13:49.917 17413-17413/com.olirwin.spartacus.deutsch E/BoostFramework: BoostFramework() : Exception_1 = java.lang.NoSuchMethodException: perfIOPrefetchStart [int, class java.lang.String]
02-28 14:13:49.923 17413-17413/com.olirwin.spartacus.deutsch I/System.out: 0
02-28 14:13:49.927 17413-17413/com.olirwin.spartacus.deutsch D/AppTracker: App Event: start
02-28 14:13:49.990 17413-17447/com.olirwin.spartacus.deutsch I/zygote64: Do partial code cache collection, code=37KB, data=47KB
02-28 14:13:49.990 17413-17447/com.olirwin.spartacus.deutsch I/zygote64: After code cache collection, code=37KB, data=47KB
02-28 14:13:49.990 17413-17447/com.olirwin.spartacus.deutsch I/zygote64: Increasing code cache capacity to 256KB
02-28 14:13:49.990 17413-17447/com.olirwin.spartacus.deutsch I/zygote64: Compiler allocated 4MB to compile void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int)
02-28 14:13:49.995 17413-17467/com.olirwin.spartacus.deutsch D/OpenGLRenderer: endAllActiveAnimators on 0x761eeb1400 (RippleDrawable) with handle 0x761e894f60
02-28 14:14:49.808 17413-17413/com.olirwin.spartacus.deutsch D/AppTracker: App Event: stop

【问题讨论】:

    标签: android exception android-activity nosuchmethoderror


    【解决方案1】:

    该错误与您的RecyclerView 未显示这一事实无关。我希望其他人知道它是什么。我建议您将适配器拆分到另一个文件中,这样您会得到如下内容:

    活动

    public class PlayerActivity extends AppCompatActivity {
    
        ArrayList<String> playerNames = new ArrayList<String>();
        Button send;
        PlayerAdapter adapter;
        RecyclerView playerList;
        String[] names;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_players);
    
            final ArrayList<Player> players = new ArrayList<Player>();
            send = findViewById(R.id.b_send);
    
            Bundle extra = new Bundle();
            final int numPlayers = extra.getInt("numPlayers");
            System.out.println(numPlayers);
            for (int i = 0; i < numPlayers; i++) {
                playerNames.add("Joueur " + (i+1) + " : ");
            }
            playerList = findViewById(R.id.player_list);
            playerList.setLayoutManager(new LinearLayoutManager(this));
            adapter = new PlayerAdapter(playerNames,this);
            playerList.setAdapter(Adapter);
            names = new String[numPlayers];
    
            Adapter.notifyDataSetChanged();
    
            send.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    for (int i = 0; i < numPlayers; i++) {
                        players.add(new Player(names[i]));
                    }
    
                    Intent intent = new Intent(view.getContext(), Score.class);
                    intent.putExtra("players", players);
                    view.getContext().startActivity(intent);
                }
            });
        }
    }
    

    适配器

    public class PlayerListAdapter extends RecyclerView.Adapter<PlayerListAdapter.ViewHolder> {
    
        private List<String> playerNames;
        private Context context;
    
        public PlayerListAdapter(ArrayList<String> playerNames, Context context) {
            this.playerNames = playerNames;
            this.context = context;
        }
    
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_cell);
            return new ViewHolder(view);
        }
    
        @Override
        public void onBindViewHolder(ViewHolder holder, int position) {
            holder.bind(this.playerNames.get(position));
    
            holder.playerName.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(
                        CharSequence charSequence, 
                        int start, 
                        int before,
                        int count) {
                    names[position] = charSequence.toString();
                }
    
                @Override
                public void onTextChanged(CharSequence charSequence, int start,
                                          int before,
                                          int count) {}
    
                @Override
                public void afterTextChanged(Editable editable) {}
            });
        }
    
        @Override
        public int getItemCount() {
            return playerNames.size();
        }
    
        class ViewHolder extends RecyclerView.ViewHolder {
    
            TextView playerLabel;
            EditText playerName;
    
            public PlayerHolder(View view) {
                super(view);
                playerLabel = view.findViewById(R.id.player_label);
                playerName = view.findViewById(R.id.player_name);
            }
    
            public void bind(String playerName) {
                playerLabel.setText(playerName);
                playerName.setHint("Nom de " + playerName);
            }
    
            public String getData(){
                return playerName.getText().toString();
            }
        }
    }
    

    提示

    如果RecyclerView 中的内容没有动态变化,您可以使用RecyclerView.setHasFixedSize(true) 来提高性能。

    给您的建议:尽量保持一致并查看 Java 编码约定。 Android Studio 具有自动格式化功能(快捷键:Windows 上的 ctrl + alt + L 或 Mac 上的 option + command + L),因此您可以使您的代码看起来更干净。

    【讨论】:

    • 嗨,你认为 RecyclerView 的内容没有显示是因为我在一个唯一的类中制作了它吗?
    • 不,但是将所有内容都塞进一个类只是一种不好的做法。你是否让它与我提供的代码一起工作?
    猜你喜欢
    • 2018-07-31
    • 2019-01-08
    • 1970-01-01
    • 1970-01-01
    • 2020-09-06
    • 2012-05-05
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    相关资源
    最近更新 更多