2016-04-28 4 views
0

Я только начал программировать для androud, но я получаю сообщение об ошибке: «Не удается разрешить метод„findViewByID (INT)“» в андроида студииНе удается разрешить метод «findViewByID (INT)» в Android Studio

Я не могу понять, что не так, попробовал настройку contentView, реализуя OnClickListenener, но ничто из этого не зафиксировало ничего.

полный код ниже, метод MainActivity, где все это происходит:

package aprivate.contract.jdeko.dww_registration; 

import android.net.Uri; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.view.View.OnClickListener; 

import com.google.android.gms.appindexing.Action; 
import com.google.android.gms.appindexing.AppIndex; 
import com.google.android.gms.common.api.GoogleApiClient; 


public class MainActivity extends AppCompatActivity{ 
    private GoogleApiClient client; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Button clickButton = (Button) findViewByID(R.id.Btn); 
     clickButton.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
      //todo 
      } 
     }); 
    } 

    @Override 
    public void onStart() { 
     super.onStart(); 

     // ATTENTION: This was auto-generated to implement the App Indexing API. 
     // See https://g.co/AppIndexing/AndroidStudio for more information. 
     client.connect(); 
     Action viewAction = Action.newAction(
       Action.TYPE_VIEW, // TODO: choose an action type. 
       "Main Page", // TODO: Define a title for the content shown. 
       // TODO: If you have web page content that matches this app activity's content, 
       // make sure this auto-generated web page URL is correct. 
       // Otherwise, set the URL to null. 
       Uri.parse("http://host/path"), 
       // TODO: Make sure this auto-generated app URL is correct. 
       Uri.parse("android-app://aprivate.contract.jdeko.dww_registration/http/host/path") 
     ); 
     AppIndex.AppIndexApi.start(client, viewAction); 
    } 

    @Override 
    public void onStop() { 
     super.onStop(); 

     // ATTENTION: This was auto-generated to implement the App Indexing API. 
     // See https://g.co/AppIndexing/AndroidStudio for more information. 
     Action viewAction = Action.newAction(
       Action.TYPE_VIEW, // TODO: choose an action type. 
       "Main Page", // TODO: Define a title for the content shown. 
       // TODO: If you have web page content that matches this app activity's content, 
       // make sure this auto-generated web page URL is correct. 
       // Otherwise, set the URL to null. 
       Uri.parse("http://host/path"), 
       // TODO: Make sure this auto-generated app URL is correct. 
       Uri.parse("android-app://aprivate.contract.jdeko.dww_registration/http/host/path") 
     ); 
     AppIndex.AppIndexApi.end(client, viewAction); 
     client.disconnect(); 
    } 

} 

ответ

2

Это просто опечатка, что вы сделали. Вы должны использовать «Id» вместо «ID».

Так что ваш

Button clickButton = (Button) findViewByID(R.id.Btn); 

Становится

Button clickButton = (Button) findViewById(R.id.Btn); 
+0

Спасибо, кажется, это было лишь небольшую ошибку, я попытался довольно хорошо провести время не заметив этого. –

0

Использование findViewById() вместо findViewByID(). есть немного орфографическая ошибка

0

Это проблема:

Button clickButton = (Button) findViewByID(R.id.Btn); 

Изменить его к этому:

Button clickButton = (Button) findViewById(R.id.Btn); 
Смежные вопросы