Reputation: 23
I only just started coding for androud, but I've been getting the error: "Cannot resolve method 'findViewByID(int)'" in android studio
I can't seem to find out what is wrong, have tried setting contentView, implementing OnClickListenener, but none of these fixed anything.
full code below, the MainActivity Method is where it all happens:
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();
}
}
Upvotes: 0
Views: 2646
Reputation: 66
It is findViewById
"Id" D should be in small letter but in your case it is in caps
Upvotes: 0
Reputation: 4926
It's just a typo that you have made. You should use "Id" instead of "ID".
So your
Button clickButton = (Button) findViewByID(R.id.Btn);
Becomes
Button clickButton = (Button) findViewById(R.id.Btn);
Upvotes: 3
Reputation: 5626
This is the problem:
Button clickButton = (Button) findViewByID(R.id.Btn);
Change it to this:
Button clickButton = (Button) findViewById(R.id.Btn);
Upvotes: -1
Reputation: 1344
Use findViewById()
instead findViewByID(). there is little spelling mistake
Upvotes: -1