沐染湫 2023-07-30 15:55 采纳率: 0%
浏览 22
已结题

No adapter attached; skipping layout

一直报错 No adapter attached; skipping layout,我不知道哪里出问题了,求指点,谢谢你们

img


package com.example.myapplication;

import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;

public class WanbanActivity extends AppCompatActivity {
    private List<price> priceList;

    private PriceAdapter adapter;
    private RecyclerView recyclerView;


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

        initView();
        connCs();

    }
    private void initView() {
        recyclerView = findViewById(R.id.recyler);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(manager);

    }
    private void showPrice(List<price> pri){
        adapter=new PriceAdapter(this,priceList);
        recyclerView.setAdapter(adapter);
    }


    public void connectwanban(){

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Document document = Jsoup.connect("http://www.xinfadi.com.cn/getPriceData.html")
                            .data("query", "Java")
                            .userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 SLBrowser/8.0.1.5162 SLBChan/11")
                            .cookie("auth", "token")
                            .timeout(8000)
                            .ignoreContentType(true)
                            .post();
                    System.out.println(document);
                    Elements el = document.getElementsByTag("body");
                    String string = el.text();
                    System.out.println(string);

                    JSONObject jsonObject= null;
                    jsonObject = new JSONObject(string);
                    StringBuilder cs=new StringBuilder();
                    int current=jsonObject.getInt("current");
                    int limit=jsonObject.getInt("limit");
                    int count=jsonObject.getInt("count");
                    JSONArray jsonArray=jsonObject.getJSONArray("list");

                    for(int i=0;i<jsonArray.length();i++){
                        JSONObject object=jsonArray.getJSONObject(i);
                        String  prodName=object.getString("prodName");

                        String  prodCatid=object.getString("prodCatid");

                        String  prodCat=object.getString("prodCat");

                        String lowPrice=object.getString("lowPrice");

                        String highPrice=object.getString("highPrice");

                        String place=object.getString("place");

                        String unitInfo=object.getString("unitInfo");

                        String pubDate=object.getString("pubDate");

                        String avgPrice=object.getString("avgPrice");
                        int id=  object.getInt("id");
                        Log.d("ting","Json======"+id+"\t"+prodName+"\t"+unitInfo+"\t"+prodCatid+"\t"+
                                prodCat+"\t"+lowPrice+"\t"+highPrice+"\t"+avgPrice+"\t"+pubDate);
                        priceList=new ArrayList<>();
                        price pri=new price();

                        pri.setid(id);
                        pri.setplace(place);
                        pri.setavgPrice(avgPrice);
                        pri.sethighPrice(highPrice);
                        pri.setlowPrice(lowPrice);
                        pri.setprodCatid(prodCatid);
                        pri.setunitInfo(unitInfo);
                        pri.setpubDate(pubDate);
                    //    pri.setprodpcatid(pri.prodpcatid);
                        pri.setprodPcat(prodCat);
                        pri.setprodName(prodName);
                        priceList.add(pri);

                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } catch (JSONException e) {
                    throw new RuntimeException(e);
                }

            }
        }).start();
    }

    private void connCs(){
        priceList=new ArrayList<>();
        Observable.create(new ObservableOnSubscribe<List<price>>() {
            @Override
            public void subscribe(@NonNull ObservableEmitter<List<price>> emitter) throws Throwable {

                    Document document = Jsoup.connect("http://www.xinfadi.com.cn/getPriceData.html")
                            .data("query", "Java")
                            .userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 SLBrowser/8.0.1.5162 SLBChan/11")
                            .cookie("auth", "token")
                            .timeout(8000)
                            .ignoreContentType(true)
                            .post();
                    System.out.println(document);
                    Elements el = document.getElementsByTag("body");
                    String string = el.text();
                    System.out.println(string);

                    JSONObject jsonObject= null;
                    jsonObject = new JSONObject(string);
                    StringBuilder cs=new StringBuilder();
                    int current=jsonObject.getInt("current");
                    int limit=jsonObject.getInt("limit");
                    int count=jsonObject.getInt("count");
                    JSONArray jsonArray=jsonObject.getJSONArray("list");
                    for(int i=0;i<jsonArray.length();i++){
                        price pri=new price();
                        JSONObject object=jsonArray.getJSONObject(i);
                        String  prodName=object.getString("prodName");

                        String  prodCatid=object.getString("prodCatid");

                        String  prodCat=object.getString("prodCat");

                        String lowPrice=object.getString("lowPrice");

                        String highPrice=object.getString("highPrice");

                        String place=object.getString("place");

                        String unitInfo=object.getString("unitInfo");

                        String pubDate=object.getString("pubDate");

                        String avgPrice=object.getString("avgPrice");
                        int id=  object.getInt("id");
                        Log.d("ting","Json======"+id+"\t"+prodName+"\t"+unitInfo+"\t"+prodCatid+"\t"+
                                prodCat+"\t"+lowPrice+"\t"+highPrice+"\t"+avgPrice+"\t"+pubDate);



                        pri.setid(id);
                        pri.setplace(place);
                        pri.setavgPrice(avgPrice);
                        pri.sethighPrice(highPrice);
                        pri.setlowPrice(lowPrice);
                        pri.setprodCatid(prodCatid);
                        pri.setunitInfo(unitInfo);
                        pri.setpubDate(pubDate);
                        //    pri.setprodpcatid(pri.prodpcatid);
                        pri.setprodPcat(prodCat);
                        pri.setprodName(prodName);
                        priceList.add(pri);
                        emitter.onNext(priceList);

                    }
            }
        }) .observeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<List<price>>() {

                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull List<price> priceList) {
                        showPrice(priceList);
                    }



                    @Override
                    public void onError(Throwable e) {


                    }

                    @Override
                    public void onComplete() {

                    }
                });
        ;
    }


}


下面是adapter


package com.example.myapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

public class PriceAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private List<price> priceList;

    private Context context;


    public PriceAdapter(Context context,List<price> obj){
        this.context=context;
        this.priceList=obj;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view= LayoutInflater.from(context).inflate(R.layout.item,parent,false);

        return new PriceHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewholder, int i) {
        PriceHolder holder= (PriceHolder) viewholder;
        final price pri=priceList.get(i);
        holder.id.setText(pri.getid());
        holder.hignPrice.setText(pri.gethignPrice());
        holder.unitInfo.setText(pri.getunitInfo());
        holder.pubDate.setText(pri.getpubDate());
        holder.prodpcatid.setText(pri.getprodpcatid());
        holder.prodPcat.setText(pri.getprodCat());
        holder.prodName.setText(pri.getprodName());
        holder.place.setText(pri.getplace());
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

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

}

holder


package com.example.myapplication;

import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class PriceHolder extends RecyclerView.ViewHolder{
    TextView id;
    TextView prodName;
    TextView proCatid;
    TextView prodCat;
    TextView prodpcatid;
    TextView prodPcat;
    TextView lowPrice;
    TextView hignPrice;
    TextView avgPrice;
    TextView place;
    TextView unitInfo;
    TextView pubDate;
    public PriceHolder(@NonNull View itemView) {
        super(itemView);
        id = itemView.findViewById(R.id.id);
        prodName = itemView.findViewById(R.id.prodName);
        prodCat = itemView.findViewById(R.id.prodCat);
        pubDate = itemView.findViewById(R.id.pubDate);
        unitInfo= itemView.findViewById(R.id.unitInfo);
        place = itemView.findViewById(R.id.place);
        avgPrice= itemView.findViewById(R.id.avgPrice);
        hignPrice = itemView.findViewById(R.id.hignPrice);
        lowPrice = itemView.findViewById(R.id.lowPrice);
        hignPrice = itemView.findViewById(R.id.hignPrice);


    }

}

  • 写回答

10条回答 默认 最新

  • Jackyin0720 2023-07-30 16:08
    关注
    获得0.75元问题酬金
    评论

报告相同问题?

问题事件

  • 系统已结题 8月7日
  • 赞助了问题酬金15元 7月30日
  • 创建了问题 7月30日

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上