我怎么想修复OnClickListener1 [英] how do I want to fix OnClickListener1

查看:102
本文介绍了我怎么想修复OnClickListener1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code。这里存在一些错误,我不可能解决。任何人都可以请帮助我吗?有一个在view.OnClickListener和视图V错误。如果我用速战速决来修复错误,就会出现另一个错误。请帮助我:'(

 包com.android;    进口java.io.BufferedReader中;
    进口java.net.InetAddress中;
    进口的java.net.UnknownHostException;
    进口java.io. *;
    进口android.app.Activity;
    进口android.os.Bundle;
    进口android.view.View.OnClickListener;
    进口android.view.View *。
    进口android.widget.EditText;
    进口android.widget.TextView;
    进口android.widget.Button;
    进口android.text.Editable;    公共类网络扩展活动实现View.OnClickListener
    {
        美国东部时间的EditText;
        TextView的文本;
        按钮平;        @覆盖
        保护无效的onCreate(捆绑savedInstanceState)//要做到自动生成的方法
        {
            super.onCreate(savedInstanceState);
            的setContentView(R.layout.main);
            EDT =(EditText上)findViewById(R.id.edt);
            文字=(TextView的)findViewById(R.id.text);
            平=(按钮)findViewById(R.id.ping);
            Button.setOnClickListener(本);
        }         公共无效的onClick(视图v)//要做到自动生成的方法
         {
         可编辑的主机= edt.getText();
         }
        InetAddress类地址= NULL;
        {
                对象主机;
                尝试
                {
                    ADDR = InetAddress.getByName(host.toString());
                }
        赶上(UnknownHostException异常E)//要做到自动生成的catch块
        {
            e.printStackTrace();
        }
        尝试
        {
            如果(addr.isReachable(5000))
            {
                text.append(\\ n+主机+-Respond OK);
            }
            其他
            {
                text.append(\\ n+主机);
            }
        }
        赶上(IOException异常五){
            text.append(\\ n+ e.toString());
        }
        尝试
        {
         字符串pingCmd =平-C5+主机;
         串pingResult =;
         运行R =调用Runtime.getRuntime();
         进程p = r.exec(pingCmd);
         在的BufferedReader =新的BufferedReader(新的InputStreamReader(p.getInputStream()));
         串inputLine;
         而((inputLine = in.readLine())!= NULL)
         {
            的System.out.println(inputLine);
            text.setText(inputLine +\\ n \\ n);
            pingResult + = inputLine;
            text.setText(pingResult);
        }
        附寄();
        }
        赶上(IOException异常E)
        {
            的System.out.println(E);
        }
            TextView的电视=新的TextView(本);
            tv.setText(\\ t \\ t \\ t \\ t **网络示踪** \\ n \\ n \\ t \\ tWelcome到Android网络示踪!);
            的setContentView(电视);
    }
    }


解决方案

如何取代这个code:

 保护无效的onCreate(捆绑savedInstanceState)//要做到自动生成的方法
        {
            super.onCreate(savedInstanceState);
            的setContentView(R.layout.main);
            EDT =(EditText上)findViewById(R.id.edt);
            文字=(TextView的)findViewById(R.id.text);
            平=(按钮)findViewById(R.id.ping);
            Button.setOnClickListener(本);
        }

本:

 保护无效的onCreate(捆绑savedInstanceState)//要做到自动生成的方法
        {
            super.onCreate(savedInstanceState);
            的setContentView(R.layout.main);
            EDT =(EditText上)findViewById(R.id.edt);
            文字=(TextView的)findViewById(R.id.text);
            平=(按钮)findViewById(R.id.ping);
            ping.setOnClickListener(本);
        }

让知道这是否正常工作。
如果没有,那么请不要往下投这样的回答:)

this is my code. there is some error here and i couldn't settle it. can anyone pls help me? there is an error at view.OnClickListener and View v. If i using quick fix to fix an error,another error will appear. pls help me :'(

package com.android;

    import java.io.BufferedReader;
    import java.net.InetAddress;
    import java.net.UnknownHostException;
    import java.io.*;
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View.OnClickListener;
    import android.view.View.*;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Button;
    import android.text.Editable;

    public class Net extends Activity implements View.OnClickListener
    {  
        EditText edt;
        TextView text;
        Button ping;

        @Override
        protected void onCreate(Bundle savedInstanceState) //To do auto generated method  
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            edt=(EditText)findViewById(R.id.edt);
            text=(TextView)findViewById(R.id.text);
            ping=(Button)findViewById(R.id.ping);
            Button.setOnClickListener(this);
        }

         public void onClick(View v) //To do auto generated method  
         {
         Editable host=edt.getText();
         }
        InetAddress addr=null;
        {
                Object host;
                try
                {
                    addr=InetAddress.getByName(host.toString());
                }
        catch(UnknownHostException e) //To do auto generated catch block
        {
            e.printStackTrace();
        }
        try
        {
            if(addr.isReachable (5000))
            {
                text.append("\n" +host+ "-Respond Ok");
            }
            else
            {
                text.append("\n"+host);
            }
        }
        catch(IOException e){
            text.append("\n"+e.toString());
        }


        try
        {
         String pingCmd="ping -c5"+host;
         String pingResult="";
         Runtime r = Runtime.getRuntime();
         Process p = r.exec(pingCmd);
         BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
         String inputLine;
         while((inputLine = in.readLine())!=null)
         {
            System.out.println(inputLine);
            text.setText(inputLine+"\n\n");
            pingResult += inputLine;
            text.setText(pingResult);
        }
        in.close();
        }
        catch(IOException e)
        {
            System.out.println(e);
        }
            TextView tv = new TextView(this);
            tv.setText("\t\t\t\t** Network Tracer ** \n\n\t\tWelcome to Android Network Tracer!");
            setContentView(tv);
    }
    }

解决方案

How about replacing this code:

protected void onCreate(Bundle savedInstanceState) //To do auto generated method  
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            edt=(EditText)findViewById(R.id.edt);
            text=(TextView)findViewById(R.id.text);
            ping=(Button)findViewById(R.id.ping);
            Button.setOnClickListener(this);
        }

with this:

protected void onCreate(Bundle savedInstanceState) //To do auto generated method  
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            edt=(EditText)findViewById(R.id.edt);
            text=(TextView)findViewById(R.id.text);
            ping=(Button)findViewById(R.id.ping);
            ping.setOnClickListener(this);
        }

Let know if this works. If not, then please dont down vote this answer :)

这篇关于我怎么想修复OnClickListener1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆