ListView代码无法使用Android Studio

时间:2017-03-26 11:18:36

标签: java android listview android-studio

我对编码很新,我有一个问题。 好的,我试图创建一个自定义ListView,其中包含一些我用jSoup解析的字符串,但由于某些原因它不起作用,它说无法解析符号CustomAdaptor。我不知道这是因为我实现了Listview类错误还是因为我在错误的地方实现了它:

package davidgb.baseballspain;


import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

//272
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);




    Button but1 = (Button) findViewById(R.id.but);
    but1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            new doit().execute();
        }
    });}


public class doit extends AsyncTask<Void, Void, Void> {
    ListView lista = (ListView)findViewById(R.id.lista);

    CustomAdapter customAdapter = new CustomAdapter();
    lista.setAdaptor(customAdaper);

    String result1;

    String result2;


    String result3;
    String result4;
    String result5;
    String result6;
    String result7;
    String result8;
    String result9;
    String result10;
    String result11;
    String result12;
    String result13;
    String result14;
    String result15;
    String result16;
    String result17;
    String result18;
    String result19;
    String result20;
    String result21;
    String result22;
    String result23;
    String result24;
    String result25;
    String result26;
    String result27;
    String result28;
    String result29;
    String result30;
    String result31;
    String result32;
    String result33;
    String result34;
    String result35;
    String result36;
    String result37;
    String result38;
    String result39;
    String result40;
    String result41;
    String result42;
    String result43;
    String result44;
    String result45;
    String result46;
    String result47;
    String result48;
    String result49;
    String result50;
    String result51;
    String result52;
    String result53;
    String result54;
    String result55;
    String result56;
    String result57;
    String result58;
    String result59;
    String result60;
    String result61;
    String result62;
    String result63;
    String result64;
    String result65;
    String result66;
    String result67;
    String result68;
    String result69;
    String result70;
    String result71;
    String result72;
    String result73;
    String result74;
    String result75;
    String result76;
    String result77;
    String result78;
    String result79;
    String result80;
    String result81;
    String result82;
    String result83;
    String result84;
    String result85;
    String result86;
    String result87;
    String result88;
    String result89;
    String result90;
    String result91;
    String result92;
    String result93;
    String result94;
    String result95;
    String result96;
    String result97;
    String result98;
    String result99;
    String result100;
    String result101;
    String result102;
    String result103;
    String result104;
    String result105;
    String result106;
    String result107;
    String result108;
    String result109;
    String result110;
    String result111;
    String result112;
    String result113;
    String result114;
    String result115;
    String result116;
    String result117;
    String result118;
    String result119;
    String result120;
    String result121;
    String result122;
    String result123;
    String result124;
    String result125;
    String result126;
    String result127;
    String result128;
    String result129;
    String result130;
    String result131;
    String result132;
    String result133;
    String result134;
    String result135;
    String result136;
    String result137;
    String result138;
    String result139;
    String result140;
    String result141;
    String result142;
    String result143;
    String result144;
    String result145;
    String result146;
    String result147;
    String result148;
    String result149;
    String result150;
    String result151;
    String result152;
    String result153;
    String result154;
    String result155;
    String result156;
    String result157;
    String result158;
    String result159;
    String result160;
    String result161;
    String result162;
    String result163;
    String result164;
    String result165;
    String result166;
    String result167;
    String result168;
    String result169;
    String result170;
    String result171;
    String result172;
    String result173;
    String result174;
    String result175;
    String result176;
    String result177;
    String result178;
    String result179;
    String result180;
    String result181;
    String result182;
    String result183;
    String result184;
    String result185;
    String result186;
    String result187;
    String result188;
    String result189;
    String result190;
    String result191;
    String result192;
    String result193;
    String result194;
    String result195;
    String result196;
    String result197;
    String result198;
    String result199;
    String result200;
    String result201;
    String result202;
    String result203;
    String result204;
    String result205;
    String result206;
    String result207;
    String result208;
    String result209;
    String result210;
    String result211;
    String result212;
    String result213;
    String result214;
    String result215;
    String result216;
    String result217;
    String result218;
    String result219;
    String result220;
    String result221;
    String result222;
    String result223;
    String result224;
    String result225;
    String result226;
    String result227;
    String result228;
    String result229;
    String result230;
    String result231;
    String result232;
    String result233;
    String result234;
    String result235;
    String result236;
    String result237;
    String result238;
    String result239;
    String result240;
    String result241;
    String result242;
    String result243;
    String result244;
    String result245;
    String result246;
    String result247;
    String result248;
    String result249;
    String result250;
    String result251;
    String result252;
    String result253;
    String result254;
    String result255;
    String result256;
    String result257;
    String result258;
    String result259;
    String result260;
    String result261;
    String result262;
    String result263;
    String result264;
    String result265;
    String result266;
    String result267;
    String result268;
    String result269;
    String result270;
    String result271;
    String result272;


        String[] resultsizq = {result1, result3, result5, result7, result9, result11, result13, result15, result17, result19, result21, result23, result25, result27, result29, result31, result33, result35, result37, result39, result41, result43, result45, result47, result49, result51, result53, result55, result57, result59, result61, result63, result65, result67, result69, result71, result73, result75, result77, result79, result81, result83, result85, result87, result89, result91, result93, result95, result97, result99, result101, result103, result105, result107, result109, result111, result113, result115, result117, result119, result121, result123, result125, result127, result129, result131, result133, result135, result137, result139, result141, result143, result145, result147, result149, result151, result153, result155, result157, result159, result161, result163, result165, result167, result169, result171, result173, result175, result177, result179, result181, result183, result185, result187, result189, result191, result193, result195, result197, result199, result201, result203, result205, result207, result209, result211, result213, result215, result217, result219, result221, result223, result225, result227, result229, result231, result233, result235, result237, result239, result241, result243, result245, result247, result249, result251, result253, result255, result257, result259, result261, result263, result265, result267, result269, result271};
        String[] resultsder = {result2, result4, result6, result8, result10, result12, result14, result16, result18, result20, result22, result24, result26, result28, result30, result32, result34, result36, result38, result40, result42, result44, result46, result48, result50, result52, result54, result56, result58, result60, result62, result64, result66, result68, result70, result72, result74, result76, result78, result80, result82, result84, result86, result88, result90, result92, result94, result96, result98, result100, result102, result104, result106, result108, result110, result112, result114, result116, result118, result120, result122, result124, result126, result128, result130, result132, result134, result136, result138, result140, result142, result144, result146, result148, result150, result152, result154, result156, result158, result160, result162, result164, result166, result168, result170, result172, result174, result176, result178, result180, result182, result184, result186, result188, result190, result192, result194, result196, result198, result200, result202, result204, result206, result208, result210, result212, result214, result216, result218, result220, result222, result224, result226, result228, result230, result232, result234, result236, result238, result240, result242, result244, result246, result248, result250, result252, result254, result256, result258, result260, result262, result264, result266, result268, result270, result272};

    class CustomAdaper extends BaseAdapter{

        @Override
        public int getCount() {
            return 0;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

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

        @Override
        public View getView(int position, View view, ViewGroup parent) {
            view = getLayoutInflater().inflate(R.layout.customlayout,null);

            TextView resultsiz= (TextView)view.findViewById(R.id.resultsiz);
            TextView resultsde= (TextView)view.findViewById(R.id.resultsde);

            resultsiz.setText(resultsizq[position]);
            resultsde.setText(resultsder[position]);

            return view;
        }
    }

    @Override
    protected Void doInBackground(Void... params) {
        try {
            Document doc = Jsoup.connect("http://www.rfebs.es/estadisticas/2017/liga/B_res.php").get();

            Elements result = doc.getElementsByClass("bianco_me");
            if (result.size() > 0) {
                // get value
                result1 = result.get(1).text();
                result2 = result.get(2).text();
                result3 = result.get(3).text();
                result4 = result.get(4).text();
                result5 = result.get(5).text();
                result6 = result.get(6).text();
                result7 = result.get(7).text();
                result8 = result.get(8).text();
                result9 = result.get(9).text();
                result10 = result.get(10).text();
                result11 = result.get(11).text();
                result12 = result.get(12).text();
                result13 = result.get(13).text();
                result14 = result.get(14).text();
                result15 = result.get(15).text();
                result16 = result.get(16).text();
                result17 = result.get(17).text();
                result18 = result.get(18).text();
                result19 = result.get(19).text();
                result20 = result.get(20).text();
                result21 = result.get(21).text();
                result22 = result.get(22).text();
                result23 = result.get(23).text();
                result24 = result.get(24).text();
                result25 = result.get(25).text();
                result26 = result.get(26).text();
                result27 = result.get(27).text();
                result28 = result.get(28).text();
                result29 = result.get(29).text();
                result30 = result.get(30).text();
                result31 = result.get(31).text();
                result32 = result.get(32).text();
                result33 = result.get(33).text();
                result34 = result.get(34).text();
                result35 = result.get(35).text();
                result36 = result.get(36).text();
                result37 = result.get(37).text();
                result38 = result.get(38).text();
                result39 = result.get(39).text();
                result40 = result.get(40).text();
                result41 = result.get(41).text();
                result42 = result.get(42).text();
                result43 = result.get(43).text();
                result44= result.get(44).text();
                result45= result.get(45).text();
                result46= result.get(46).text();
                result47= result.get(47).text();
                result48= result.get(48).text();
                result49= result.get(49).text();
                result50= result.get(50).text();
                result51= result.get(51).text();
                result52= result.get(52).text();
                result53= result.get(53).text();
                result54= result.get(54).text();
                result55= result.get(55).text();
                result56= result.get(56).text();
                result57= result.get(57).text();
                result58= result.get(58).text();
                result59= result.get(59).text();
                result60= result.get(60).text();
                result61= result.get(61).text();
                result62= result.get(62).text();
                result63= result.get(63).text();
                result64= result.get(64).text();
                result65= result.get(65).text();
                result66= result.get(66).text();
                result67= result.get(67).text();
                result68= result.get(68).text();
                result69= result.get(69).text();
                result70= result.get(70).text();
                result71= result.get(71).text();
                result72= result.get(72).text();
                result73= result.get(73).text();
                result74= result.get(74).text();
                result75= result.get(75).text();
                result76= result.get(76).text();
                result77= result.get(77).text();
                result78= result.get(78).text();
                result79= result.get(79).text();
                result80= result.get(80).text();
                result81= result.get(81).text();
                result82= result.get(82).text();
                result83= result.get(83).text();
                result84= result.get(84).text();
                result85= result.get(85).text();
                result86= result.get(86).text();
                result87= result.get(87).text();
                result88= result.get(88).text();
                result89= result.get(89).text();
                result90= result.get(90).text();
                result91= result.get(91).text();
                result92= result.get(92).text();
                result93= result.get(93).text();
                result94= result.get(94).text();
                result95= result.get(95).text();
                result96= result.get(96).text();
                result97= result.get(97).text();
                result98= result.get(98).text();
                result99= result.get(99).text();
                result100 = result.get(100).text();
                result101 = result.get(101).text();
                result102 = result.get(102).text();
                result103 = result.get(103).text();
                result104 = result.get(104).text();
                result105 = result.get(105).text();
                result106 = result.get(106).text();
                result107 = result.get(107).text();
                result108 = result.get(108).text();
                result109 = result.get(109).text();
                result110 = result.get(110).text();
                result111= result.get(111).text();
                result112= result.get(112).text();
                result113= result.get(113).text();
                result114= result.get(114).text();
                result115= result.get(115).text();
                result116= result.get(116).text();
                result117= result.get(117).text();
                result118= result.get(118).text();
                result119= result.get(119).text();
                result120= result.get(120).text();
                result121= result.get(121).text();
                result122= result.get(122).text();
                result123= result.get(123).text();
                result124= result.get(124).text();
                result125= result.get(125).text();
                result126= result.get(126).text();
                result127= result.get(127).text();
                result128= result.get(128).text();
                result129= result.get(129).text();
                result130= result.get(130).text();
                result131= result.get(131).text();
                result132= result.get(132).text();
                result133= result.get(133).text();
                result134= result.get(134).text();
                result135= result.get(135).text();
                result136= result.get(136).text();
                result137= result.get(137).text();
                result138= result.get(138).text();
                result139= result.get(139).text();
                result140= result.get(140).text();
                result141= result.get(141).text();
                result142= result.get(142).text();
                result143= result.get(143).text();
                result144= result.get(144).text();
                result145= result.get(145).text();
                result146= result.get(146).text();
                result147= result.get(147).text();
                result148= result.get(148).text();
                result149= result.get(149).text();
                result150= result.get(150).text();
                result151= result.get(151).text();
                result152= result.get(152).text();
                result153= result.get(153).text();
                result154= result.get(154).text();
                result155= result.get(155).text();
                result156= result.get(156).text();
                result157= result.get(157).text();
                result158= result.get(158).text();
                result159= result.get(159).text();
                result160= result.get(160).text();
                result161= result.get(161).text();
                result162= result.get(162).text();
                result163= result.get(163).text();
                result164= result.get(164).text();
                result165= result.get(165).text();
                result166= result.get(166).text();
                result167= result.get(167).text();
                result168= result.get(168).text();
                result169= result.get(169).text();
                result170= result.get(170).text();
                result171= result.get(171).text();
                result172= result.get(172).text();
                result173= result.get(173).text();
                result174= result.get(174).text();
                result175= result.get(175).text();
                result176= result.get(176).text();
                result177= result.get(177).text();
                result178= result.get(178).text();
                result179= result.get(179).text();
                result180= result.get(180).text();
                result181= result.get(181).text();
                result182= result.get(182).text();
                result183= result.get(183).text();
                result184= result.get(184).text();
                result185= result.get(185).text();
                result186= result.get(186).text();
                result187= result.get(187).text();
                result188= result.get(188).text();
                result189= result.get(189).text();
                result190= result.get(190).text();
                result191= result.get(191).text();
                result192= result.get(192).text();
                result193= result.get(193).text();
                result194= result.get(194).text();
                result195= result.get(195).text();
                result196= result.get(196).text();
                result197= result.get(197).text();
                result198= result.get(198).text();
                result199= result.get(199).text();
                result200 = result.get(200).text();
                result201 = result.get(201).text();
                result202 = result.get(202).text();
                result203 = result.get(203).text();
                result204 = result.get(204).text();
                result205 = result.get(205).text();
                result206 = result.get(206).text();
                result207 = result.get(207).text();
                result208 = result.get(208).text();
                result209 = result.get(209).text();
                result210 = result.get(210).text();
                result211= result.get(211).text();
                result212= result.get(212).text();
                result213= result.get(213).text();
                result214= result.get(214).text();
                result215= result.get(215).text();
                result216= result.get(216).text();
                result217= result.get(217).text();
                result218= result.get(218).text();
                result219= result.get(219).text();
                result220= result.get(220).text();
                result221= result.get(221).text();
                result222= result.get(222).text();
                result223= result.get(223).text();
                result224= result.get(224).text();
                result225= result.get(225).text();
                result226= result.get(226).text();
                result227= result.get(227).text();
                result228= result.get(228).text();
                result229= result.get(229).text();
                result230= result.get(230).text();
                result231= result.get(231).text();
                result232= result.get(232).text();
                result233= result.get(233).text();
                result234= result.get(234).text();
                result235= result.get(235).text();
                result236= result.get(236).text();
                result237= result.get(237).text();
                result238= result.get(238).text();
                result239= result.get(239).text();
                result240= result.get(240).text();
                result241= result.get(241).text();
                result242= result.get(242).text();
                result243= result.get(243).text();
                result244= result.get(244).text();
                result245= result.get(245).text();
                result246= result.get(246).text();
                result247= result.get(247).text();
                result248= result.get(248).text();
                result249= result.get(249).text();
                result250= result.get(250).text();
                result251= result.get(251).text();
                result252= result.get(252).text();
                result253= result.get(253).text();
                result254= result.get(254).text();
                result255= result.get(255).text();
                result256= result.get(256).text();
                result257= result.get(257).text();
                result258= result.get(258).text();
                result259= result.get(259).text();
                result260= result.get(260).text();
                result261= result.get(261).text();
                result262= result.get(262).text();
                result263= result.get(263).text();
                result264= result.get(264).text();
                result265= result.get(265).text();
                result266= result.get(266).text();
                result267= result.get(267).text();
                result268= result.get(268).text();
                result269= result.get(269).text();
                result270= result.get(270).text();
                result271= result.get(271).text();
                result272= result.get(272).text();


            }


        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}}

编辑:拼错了适配器。还将所有这些字符串存储在一个数组中,这样更好更清洁。

2 个答案:

答案 0 :(得分:1)

> task1 [error] task1 original output [success] Total time: 0 s, completed Mar 26, 2017 1:50:53 PM > task2 [error] task1 original output [error] task2 original output [error] task2 chain1 before task1.value [error] task2 chain1 before task2.value [error] task2 chain2 before task1.value [error] task2 chain2 before task2.value [error] task2 chain2 before task2.value [success] Total time: 0 s, completed Mar 26, 2017 1:50:56 PM 的简单拼写错误
adaptor

还考虑使用ArrayList存储所有这些字符串

答案 1 :(得分:1)

你有2个错误的拼写。根据您为适配器命名的方式,首先.setAdaptor它应该是.setAdapter秒在方括号(customAdaper)内它应该是(customAdapter)。使用Android Studio Intellisense可以避免错误拼写。 还可以考虑使用数组或列表来简化代码。并在AsyncTask中覆盖postExecute方法并在那里填充适配器。像这样:

@Override
    protected void onPostExecute(Void aVoid) {  
   CustomAdapter customAdapter = new CustomAdapter();
   lista.setAdapter(customAdapter); 
 }