Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法在改装中获得响应,并且获取未连接布局管理器的错误跳过布局_Android_Android Layout_Android Recyclerview_Retrofit - Fatal编程技术网

Android 无法在改装中获得响应,并且获取未连接布局管理器的错误跳过布局

Android 无法在改装中获得响应,并且获取未连接布局管理器的错误跳过布局,android,android-layout,android-recyclerview,retrofit,Android,Android Layout,Android Recyclerview,Retrofit,无法使用改型获取JSON数据布局中附加适配器的问题。我在清单文件中提到了Internet权限以及在gradle中导入所有必需的库 我的日志: E/RecyclerView: No adapter attached; skipping layout W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/graphics/drawable/Icon;) I/dalvikvm: Could not find m

无法使用改型获取JSON数据布局中附加适配器的问题。我在清单文件中提到了Internet权限以及在gradle中导入所有必需的库

我的日志:

E/RecyclerView: No adapter attached; skipping layout
 W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/graphics/drawable/Icon;)
I/dalvikvm: Could not find method android.widget.ImageView.setImageIcon, referenced from method android.support.v7.widget.AppCompatImageView.setImageIcon
W/dalvikvm: VFY: unable to resolve virtual method 13331: Landroid/widget/ImageView;.setImageIcon (Landroid/graphics/drawable/Icon;)V
D/dalvikvm: VFY: replacing opcode 0x6f at 0x0000
**E/RecyclerView: No adapter attached; skipping layout**
**D/com.example.chintankotadia.apidemo.activity.MainActivity: onResponse:[com.example.chintankotadia.apidemo.model.Example@4221c8b8, com.example.chintankotadia.apidemo.model.Example@4221c920, com.example.chintankotadia.apidemo.model.Example@4221c940, com.example.chintankotadia.apidemo.model.Example@4221c988, com.example.chintankotadia.apidemo.model.Example@4221c9e8, com.example.chintankotadia.apidemo.model.Example@4221ca08, com.example.chintankotadia.apidemo.model.Example@4221ca68, com.example.chintankotadia.apidemo.model.Example@4221ca88, com.example.chintankotadia.apidemo.model.Example@4221caa8, com.example.chintankotadia.apidemo.model.Example@4221cb30, com.example.chintankotadia.apidemo.model.Example@4221ccb0, com.example.chintankotadia.apidemo.model.Example@4221ccd0, com.example.chintankotadia.apidemo.model.Example@4221cd70, com.example.chintankotadia.apidemo.model.Example@4221cd90, com.example.chintankotadia.apidemo.model.Example@4221cdb0, com.example.chintankotadia.apidemo.model.Example@4221d690, com.example.chintankotadia.apidemo.model.Example@422**
**E/RecyclerView: No layout manager attached; skipping layout**
D/dalvikvm: GC_CONCURRENT freed 292K, 11% free 7902K/8839K, paused 3ms+2ms, total 37ms
W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
W/IInputConnectionWrapper: setComposingText on inactive InputConnection
W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
我的代码:

MainActivity.java

 public class MainActivity extends AppCompatActivity {

   private static final String TAG = MainActivity.class.getName();
            private List<Example> list;
            private RecyclerView recyclerView;
            private MainAdapter adapter;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                recyclerView = findViewById(R.id.rv_demo);
                list = new ArrayList<>();
                loadResponse();
            }

            private void loadResponse() {

            Retrofit retrofit = new Retrofit.Builder()
                 .baseUrl("http://jsonplaceholder.typicode.com")    
                 .addConverterFactory(GsonConverterFactory.create())
                 .build();
            ReqInterface request = 
                 retrofit.create(ReqInterface.class);

            Call<List<Example>> call = request.getMyJSON();

            call.enqueue(new Callback<List<Example>>() {

            @Override
            public void onResponse(Call<List<Example>> call, 
                       Response<List<Example>> response) {

            if (response.isSuccessful()) {


            List<Example> exampleList = response.body();
            Example example = null;

            for (int i = 0; i < exampleList.size(); i++) {

             example = new Example();
             String userid = 
             String.valueOf(exampleList.get(i).getUserId());
             String title = exampleList.get(i).getTitle();
             String body = exampleList.get(i).getBody();                   
             example.setUserId(Integer.valueOf(userid));
             example.setTitle(title);
             example.setBody(body);
             list.add(example);
        }
        Log.d(TAG, "onResponse:" + list);
        adapter = new MainAdapter(MainActivity.this, list);
        recyclerView.setAdapter(adapter);
        adapter.notifyDataSetChanged();
       } else {
         try {

       JSONObject jObjError = new 
            JSONObject(response.errorBody().string());
       Toast.makeText(MainActivity.this, 
       jObjError.getString("message"), Toast.LENGTH_LONG).show();

      } catch (Exception e) {
       Toast.makeText(MainActivity.this, e.getMessage(), 
           Toast.LENGTH_LONG).show();
         }
       }
      }

      @Override
        public void onFailure(Call<List<Example>> call, Throwable t) 
        {
           Toast.makeText(MainActivity.this, "Error in fetching 
            data", Toast.LENGTH_SHORT).show();
                    }
                });
            }
   }

您需要将
LayoutManager
添加到
RecyclerView

尝试添加以下内容:

recyclerView.setLayoutManager(new LinearLayoutManager(this));

仅供参考,还有更多可用的
LayoutManager
,而不仅仅是
LinearLayoutManager

,您需要在
回收视图中添加
LayoutManager

尝试添加以下内容:

recyclerView.setLayoutManager(new LinearLayoutManager(this));

仅供参考,还有更多可用的
LayoutManager
,而不仅仅是
LinearLayoutManager

您必须将布局管理器添加到回收视图中 从xml


您必须将布局管理器添加到您的Recycle Service 从xml

在活动的
onCreate()

recyclerView = findViewById(R.id.rv_demo);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
在活动的
onCreate()

recyclerView = findViewById(R.id.rv_demo);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);

可能的重复可能的重复谢谢你的解决方案谢谢你的解决方案
<android.support.v7.widget.RecyclerView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layoutManager="android.support.v7.widget.LinearLayoutManager" >
LinearLayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
mRecyclerView.setLayoutManager(mLayoutManager);
recyclerView = findViewById(R.id.rv_demo);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);