2017-09-12 15 views
0

ボタンをクリックすると、nullのshwoingエラーです。 私はなぜこの質問が再びポリシーであると言ってスタックオーバーフローを知りません。setonclicklistenerはボタンをクリックしてクリックしないでください

Mainactivityコード

  Button bnt = findViewById(android.R.id.button1); 
      bnt.setOnClickListener(new OnClickListener() 

      { 

       WebView web1; 
       EditText editText = findViewById(android.R.id.edit); 
        public void onClick(final View view) { 

         String Address = "http://" + editText.getText().toString(); 
         web1 = (WebView) findViewById(R.id.webview); 

         WebSettings webSetting = web1.getSettings(); 
         webSetting.setBuiltInZoomControls(true); 
         webSetting.setJavaScriptEnabled(true); 
         web1.setWebViewClient(new WebViewClient()); 
         web1.loadUrl(Address); 

        } 


      }); 

     } 

XMLコード

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:text="@string/go" /> 



<WebView 
    android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_marginTop="50dip" /> 

私のエラーが

E/AndroidRuntimeです:致命的な例外:メイン

           java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference 

ありがとうございます

+1

可能な重複しなければなりません

EditText editText = findViewById(android.R.id.edit); 

EditText editText = findViewById(R.id.edit); 

この

Button bnt = findViewById(android.R.id.button1); 

である必要があり、そのIDからAndroidのプレフィックスを削除する必要があります、どうすれば修正できますか?](https:///stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – FWeigl

+0

誰かのためにデバッグするサイトポリシー違反です.https://stackoverflow.com/help/オントピック –

答えて

0

編集テキストとボタンを間違った方法で初期化しています。あなたは、NullPointerExceptionが何である[の

Button bnt = findViewById(R.id.button1); 
関連する問題