Cannot resolve method “findViewById” in MainActivity

I’m suddenly getting “cannot resolve” errors for findViewById(int) and setContentView(). I don’t want to get into the knitty gritty of what my app does, but it was running fine until suddenly it wasn’t after some time working on unrelated functions, with no changes made to the code. I tried reverting to a previous day when I was able to get the code to run, but the issue persists.

I’ve looked through a lot of help threads, and I’ve tried the “Invalidate Caches/Restart” option, but that didn’t have any effect unfortunately

public class MainActivity extends FragmentActivity{

    protected void onCreate(@Nullable Bundle savedInstanceState) {
        myVib = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
        myDialog = new Dialog(this);
        displayFragment = (inputsFragment) getSupportFragmentManager().findFragmentById(;
        progressBar = findViewById(;
        ShowPopup(findViewById(, -1);

this.getSystemService(VIBRATOR_SERVICE) now gives the error, “cannot resolve getSystemService in MainActivity”, for presumably the same reason.

In addition, activity android:name=”.MainActivity” in my manifest now gives the error: “MainActivity must extend” This seems strange, since to my understanding FragmentActivity inherits Activity

<manifest xmlns:android=""

        android:theme="@style/AppTheme" >
        <activity android:name=".MainActivity">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
    <uses-permission android:name="android.permission.VIBRATE"/>


Source: Android Questions

Author Details

admin photo

Sobuj Ali

Founder & CEO

Sobuj Ali is Founder & CEO at I have a good knowledge of Marketing. So I provide all Technology information on their website.

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Rating: