2012-02-20 10 views
0

これは私のコードです。ここにいくつかのエラーがあり、私はそれを解決することができませんでした。誰でも私を助けることができますか? view.OnClickListenerとView v。でエラーが発生しました。クイックフィックスを使用してエラーを修正すると、別のエラーが表示されます。 plsは私を助ける: '(どのように私は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); 
    } 
    } 
+0

エラーは何ですか? logcat –

+0

をview.OnClickListenerビューでエラーを送信するv Button.setOnClickListener –

答えて

0

をエラーがライン上におそらくここで、時間をコンパイルしている場合:次のすべてのコードを配置したい場合は、唯一の文を持つメソッドの定義を閉じた

public void onClick(View v) //To do auto generated method 
    { 
    Editable host=edt.getText(); 
    } 
    InetAddress addr=null; 

onClickメソッドに、次のように:

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); 
} 
0

どのようにこのコード交換について:

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); 
     } 

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); 
     } 

これが動作するかどうか知ってみましょう:これで

。 そうでない場合は、この回答を投票しないでください:)

+0

はまだsetOnClickListenerでエラーが発生している –

+0

ping.setOnClickListenerにログ –

+0

エラーが表示されます(setOnClickListenerの下に赤い線が表示されます) –

関連する問題