這是我的代碼。這裏有一些錯誤,我無法解決它。任何人都可以幫助我嗎? view.OnClickListener和View v中存在錯誤。如果我使用快速修復來修復錯誤,則會出現另一個錯誤。請幫助我:'(我該如何解決OnClickListener1
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);
}
}
什麼錯誤?發佈您的logcat – 2012-02-20 07:25:24
錯誤在view.OnClickListener查看v Button.setOnClickListener – 2012-02-20 07:29:51