Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.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
Java 无法从类型活动对非静态方法findViewById(int)进行静态引用_Java_Android - Fatal编程技术网

Java 无法从类型活动对非静态方法findViewById(int)进行静态引用

Java 无法从类型活动对非静态方法findViewById(int)进行静态引用,java,android,Java,Android,我的(第一次)主要活动中有一次点击。在这里,我从另一个(第二个)活动类调用pay()方法。我在这里调用这个方法,因为我在这个类方法中传递它的值 tvdel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { TableRow km= (TableRow)findViewById(tr.getId());

我的(第一次)主要活动中有一次点击。在这里,我从另一个(第二个)活动类调用pay()方法。我在这里调用这个方法,因为我在这个类方法中传递它的值

tvdel.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        TableRow km= (TableRow)findViewById(tr.getId());                
        second.pay(dist1[km.getId()], pan1[km.getId()], taxno1[km.getId()],"N");
        pay2(dist1[km.getId()], pan1[km.getId()], taxno1[km.getId()],"N");
    }
});
然后,如果将text设置为文本视图,则会出现此错误

错误:无法从类型活动对非静态方法findViewById(int)进行静态引用

TextView test = (TextView)findViewById(R.id.otaxno);
test.setText("try");
我尝试了许多解决方案,但对我的情况毫无帮助。请帮忙

我的主要活动课:

public String property(String taxtype, final String userid) {

    final String NAMESPACE = "http://tempuri.org/";
    final String URL = "http://192.168.1.1/JavaService/Service.asmx";
    final String SOAP_ACTION = "http://tempuri.org/GetTaxTypeDetails";
    final String METHOD_NAME = "GetTaxTypeDetails";


    Typeface tfavv = Typeface.createFromAsset(getAssets(),"fonts/Avvaiyar.ttf");


    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    request.addProperty("sDistrict", dis);
    request.addProperty("sPanchayat", pan);
    request.addProperty("sTaxType", taxtype);
    request.addProperty("sTaxNo", taxno);
    request.addProperty("sTaxName", taxname);
    request.addProperty("sUserId", userid);

    DisAndPanDetails C = new DisAndPanDetails();
    PropertyInfo pi = new PropertyInfo();
    pi.setName("DisAndPanDetails");
    pi.setValue(C);
    pi.setType(C.getClass());
    request.addProperty(pi);
    SoapSerializationEnvelope envelope2 = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope2.dotNet = true;
    envelope2.setOutputSoapObject(request);
    envelope2.addMapping(NAMESPACE, "DisAndPanDetails", new DisAndPanDetails().getClass());
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true;

    try {
        androidHttpTransport.call(SOAP_ACTION, envelope2);
        SoapObject response2 = (SoapObject) envelope2.getResponse();

        Log.i("myApp", response2.toString());
        System.out.println("check dddddddddddddd" + response2);

        envelope2.addMapping(NAMESPACE, "Panchayat",new DisAndPanDetails().getClass());
        androidHttpTransport.call(SOAP_ACTION, envelope2);
        final DisAndPanDetails[] personList2 = new DisAndPanDetails[response2.getPropertyCount()];

        for (int j = 0; j < personList2.length; j++) {
            SoapObject so = (SoapObject) response2.getProperty(j);
            DisAndPanDetails person2 = new DisAndPanDetails();
            person2.TaxNo = so.getProperty(0).toString();
            person2.TaxName= so.getPropertyAsString(1).toString();
            person2.NoData=so.getPropertyAsString(6).toString();
            person2.District=so.getPropertyAsString(7).toString();
            person2.Panchayat=so.getPropertyAsString(8).toString();
            person2.TaxType=so.getPropertyAsString(9).toString();
            person2.TaxStatus=so.getPropertyAsString(10).toString();
            personList2[j] = person2;
        }


        final String[] taxno1 = new String[personList2.length];
        String[] taxname1 = new String[personList2.length];
         dist1 = new String[personList2.length];
        final String[] pan1 = new String[personList2.length];
        final String[] taxtype1 = new String[personList2.length];
        String[] status1 = new String[personList2.length];


        System.out.println("stringarray: " + taxno1);
        String Nod = null;

        for (int i = 0; i < personList2.length; i++) 
        {

            taxno1[i] = Arrays.asList(personList2[i].TaxNo).toString().replace("[", "").replace("]", "");
            taxname1[i] = Arrays.asList(personList2[i].TaxName).toString().replace("[", "").replace("]", "");
            dist1[i] = Arrays.asList(personList2[i].District).toString().replace("[", "").replace("]", "");
            pan1[i] = Arrays.asList(personList2[i].Panchayat).toString().replace("[", "").replace("]", "");
            taxtype1[i] = Arrays.asList(personList2[i].TaxType).toString().replace("[", "").replace("]", "");
            status1[i] = Arrays.asList(personList2[i].TaxStatus).toString().replace("[", "").replace("]", "");
            Nod = personList2[i].NoData.toString();

            System.out.println(taxno1[i]);
            System.out.println(taxname1[i]);
            System.out.println(dist1[i]);
            System.out.println(pan1[i]);
            System.out.println(taxtype1[i]);
            System.out.println(status1[i]);
            System.out.println("nod"+Nod);

        }






        TableLayout ll = (TableLayout) findViewById(R.id.tablelayout1);


        if ( Nod.equals("0"))
        {}
        else 
        {
       for (i = 0; i < personList2.length; i++)
            {
        final TableRow tr = new TableRow(this);

//       final TableRow tr = (TableRow)findViewById(R.id.tabrow2);
          LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

          tr.setId(i);


          tr.setLayoutParams(lp);
          lp.setMargins(10, -10, 15, 5);


          final TextView tvLeft = new TextView(this);
          tvLeft.setLayoutParams(lp);
          tvLeft.setGravity(Gravity.CENTER);
          tvLeft.setText(taxno1[i]);


          final TextView tvCenter = new TextView(this);
          tvCenter.setLayoutParams(lp);
          tvCenter.setTypeface(tfavv);
          tvCenter.setText(taxname1[i]);


          final TextView tvRight = new TextView(this);
          tvRight.setLayoutParams(lp);
          tvRight.setText(pan1[i]);


          final TextView tvend = new TextView(this);
          tvend.setLayoutParams(lp);
          tvend.setText(dist1[i]);


          final TextView tvdel = new TextView(this);
          tvdel.setLayoutParams(lp);
          tvdel.setTextSize(20);
          tvdel.setGravity(Gravity.CENTER);
          tvdel.setTextColor(Color.GREEN);
          tvdel.setText("Pay");



          tvdel.setOnClickListener(new View.OnClickListener() {

              @Override
              public void onClick(View v) {

                Intent login = new Intent(getApplicationContext(), PropertyTaxpay.class);
                login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                login.putExtra("no",taxno1);
                startActivity(login);
                TableRow km= (TableRow)findViewById(tr.getId());                
                System.out.println(km);                   
                System.out.println("clickeddddddddddd  tr"+tr.getId());
                System.out.println("clickeddddddddddd  km "+km.getId());
                System.out.println("clickeddddddddddd  i"+i);
                PropertyTaxpay.pay(dist1[km.getId()], pan1[km.getId()], taxno1[km.getId()],"P");
            //  pay2(dist1[km.getId()], pan1[km.getId()], taxno1[km.getId()],"P");
              }
          }
     );

          tr.addView(tvLeft);
          tr.addView(tvCenter);
          tr.addView(tvRight);
          tr.addView(tvend);
          tr.addView(tvdel);

          ll.addView(tr, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

        }












        for (int i = 0; i < personList2.length; i++) 
        {
            System.out.println("last TaxNo: " + personList2[i].TaxNo);
            System.out.println("last TaxName: " + personList2[i].TaxName);
            System.out.println("last District: "+ personList2[i].District);
            System.out.println("last Panchayat: "   + personList2[i].Panchayat);
            System.out.println("last TaxType: " + personList2[i].TaxType);
            System.out.println("last TaxStatus: "   + personList2[i].TaxStatus);
            System.out.println(" ");
            System.out.println(" ");
            System.out.println(" ");
            System.out.println(" ");
            System.out.println(" ");
        }
}
    }

        catch (SocketException ex) {
            Log.e("Error : ", "Error on soapPrimitiveData() " + ex.getMessage());
            ex.printStackTrace();
        } catch (Exception e) {
            Log.e("Error : ", "Error soapPrimitiveData() " + e.getMessage());
            e.printStackTrace();
        }
        return null;
    }
protected static String pay(String dist, String pan,String taxno, String taxtype ) {

    final String NAMESPACE = "http://tempuri.org/";
    final String URL = "http://192.168.1.1/JavaService/Service.asmx";
    final String SOAP_ACTION = "http://tempuri.org/GetTaxDetails";
    final String METHOD_NAME = "GetTaxDetails";

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    request.addProperty("sDistrict", dist);
    request.addProperty("sPanchayat", pan);
    request.addProperty("sTaxType", taxtype);
    request.addProperty("sTaxNo", taxno);


    DisAndPanDetails D = new DisAndPanDetails();
    PropertyInfo pi = new PropertyInfo();
    pi.setName("DisAndPanDetails");
    pi.setValue(D);
    pi.setType(D.getClass());
    request.addProperty(pi);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;

    envelope.setOutputSoapObject(request);
    System.out.println(request);
    envelope.addMapping(NAMESPACE, "DisAndPanDetails",  new DisAndPanDetails().getClass());
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true;

    try {
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapObject response2 = (SoapObject) envelope.getResponse();

        Log.i("myApp", response2.toString());
        System.out.println("clicvvvvvvvv dddddddddddddd" + response2);
        String resultData = response2.getProperty(0).toString(); 

        System.out.println("clicvvvvvvvv resultData" + resultData);

         DisAndPanDetails[] personList2 = new DisAndPanDetails[response2.getPropertyCount()];


        for (int j = 0; j < personList2.length; j++) {
            DisAndPanDetails person2 = new DisAndPanDetails();
            person2.TaxName= response2.getProperty(0).toString();
            person2.TaxDoorNo=response2.getProperty(1).toString();
            person2.TaxStreetName=response2.getPropertyAsString(2).toString();
            person2.TaxWardNo=response2.getPropertyAsString(3).toString();
            person2.Error=response2.getPropertyAsString(4).toString();
            person2.MobileNo=response2.getPropertyAsString(5).toString();
            person2.NoData=response2.getPropertyAsString(6).toString();
            person2.NonTaxRights=response2.getPropertyAsString(7).toString();
            personList2[j] = person2;
        }

        String TaxName1 ;
        String TaxDoorNo1 ;
        String TaxStreetName1 ;
        String TaxWardNo1 ;
        String NonTaxRights1 ;
        String NoData1;
        String Error1;
        String MobileNo1;

        int i=0;
            TaxName1 = personList2[i].TaxName.toString();
            TaxDoorNo1 = personList2[i].TaxDoorNo.toString();
            TaxStreetName1 = personList2[i].TaxStreetName.toString();
            TaxWardNo1 = personList2[i].TaxWardNo.toString();
            NonTaxRights1 = personList2[i].NonTaxRights.toString();
            NoData1 = personList2[i].NoData.toString();
            Error1 = personList2[i].Error.toString();
            MobileNo1 = personList2[i].MobileNo.toString();

            System.out.println("TaxName1"+TaxName1);
            System.out.println("TaxDoorNo1"+TaxDoorNo1);
            System.out.println("TaxStreetName1"+TaxStreetName1);
            System.out.println("TaxWardNo1"+TaxWardNo1);
            System.out.println("NonTaxRights1"+NonTaxRights1);
            System.out.println("NoData1"+NoData1);
            System.out.println("Error1"+Error1);
            System.out.println("MobileNo1"+MobileNo1);


        /*  LayoutInflater inflater =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View v = inflater.inflate(R.layout.payment, null);
            TextView test = (TextView)v.findViewById(R.id.otaxno);
            test.setText("try");


            */


    TextView test = (TextView)getActivity().findViewById(R.id.otaxno);
            test.setText("try");





    }
    catch (SocketException ex) {
        Log.e("Error : ", "Error on soapPrimitiveData() " + ex.getMessage());
        ex.printStackTrace();
    } catch (Exception e) {
        Log.e("Error : ", "Error  soapPrimitiveData() " + e.getMessage());
        e.printStackTrace();
    }

    return null;
公共字符串属性(字符串分类类型,最终字符串用户ID){
最终字符串名称空间=”http://tempuri.org/";
最终字符串URL=”http://192.168.1.1/JavaService/Service.asmx";
最后一个字符串SOAP_ACTION=”http://tempuri.org/GetTaxTypeDetails";
最终字符串方法\u NAME=“GetTaxTypeDetails”;
Typeface tfavv=Typeface.createFromAsset(getAssets(),“font/Avvaiyar.ttf”);
SoapObject请求=新的SoapObject(名称空间、方法名称);
请求.addProperty(“sDistrict”,dis);
请求添加属性(“sPanchayat”,pan);
addProperty(“statxType”,taxtype);
请求。添加属性(“sTaxNo”,taxno);
request.addProperty(“StatxName”,taxname);
addProperty(“sUserId”,userid);
DisAndPanDetails C=新的DisAndPanDetails();
PropertyInfo pi=新的PropertyInfo();
pi.集合名(“DisAndPanDetails”);
pi.设定值(C);
setType(C.getClass());
请求。添加属性(pi);
SOAPSerializationEnvelope2=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope2.dotNet=true;
envelope2.setOutputSoapObject(请求);
addMapping(名称空间,“DisAndPanDetails”,新的DisAndPanDetails().getClass());
HttpTransportSE androidHttpTransport=新的HttpTransportSE(URL);
androidHttpTransport.debug=true;
试一试{
调用(SOAP_操作,信封2);
SoapObject response2=(SoapObject)envelope2.getResponse();
Log.i(“myApp”,response2.toString());
System.out.println(“check dddddddddd”+response2);
addMapping(名称空间,“Panchayat”,新DisAndPanDetails().getClass());
调用(SOAP_操作,信封2);
最终DisAndPanDetails[]personList2=新DisAndPanDetails[response2.getPropertyCount()];
对于(int j=0;j  public class PropertyTax extends Activity{
       private static TextView test=null;
       @Override
       public void onCreate(Bundle savedInstanceState) {
        //CODE
        test=(TextView)findViewById(R.id.otaxno);
        ...
       }
    }
test.setText("try");