How do you change the theme of an app in Android Studio without getting rendering problems?

I have been having this problem in Android studio where I create a project, and I try to change the theme but it always gives me rendering problems. I try to change the styles.xml but it doesn't really seem to work. Here's the theme I want: Material Light

Whenever I try to select it, I get rendering problems: Rendering Problems

Here's the error details:

java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:36)
at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:192)
at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:186)
at sun.reflect.GeneratedConstructorAccessor271.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:465)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:172)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:186)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:334)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:345)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:245)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:324)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$72(RenderTask.java:659)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

As seen from the first line of the error log, it says

java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.

So, Naturally I select the Appcompat Theme like so: AppCompat

And this works without any problems: AppCompat Theme

MainActivity.java file as requested:

 package com.example.moham.currencyconverter;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

       FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

How can I make sure that I can use any theme I want and make it work without rendering problems?

edited the java file to extend Activity, and that didn' solve the problem. Instead, I now have an additional problem in the java code: enter image description here java file


ANSWERS:


As @CommonsWare and @Vishal Puri explain to you , your problem should solve if you Change

public class MainActivity extends AppCompatActivity {

To

public class MainActivity extends Activity {

As @CommonsWare rightly mentioned, your activity is extending AppCombatActivity due to which you have to use AppCombat theme.

Simply extend Activity instead of AppCombatActivity. It'll solve your problem.

But prefer to use AppCombatActivity as you'll be able to easily use design widgets like floatingActionButton, etc. Without AppCombat theme and activity you'll not be able to use them. Hope it helps.

Check this link, link2 to know why to use AppCombatActivity instead of ActionBarActivity, Activity, etc.



 MORE:


 ? Dialog theme animation issue
 ? Can I change color of Android menu dynamically?
 ? How can i allow user to change button's color in an android app
 ? Unable to start MainActivity - You need to use a Theme.AppCompat theme (or descendant) with this activity
 ? How to customize the background of the floating ActionBar?
 ? How to support only Lollipop on Android?
 ? How to set global application background color?
 ? Accessing xml theme's parent
 ? How to extract the source code of Theme.DeviceDefault.Light.NoActionBar?
 ? Add custom widget styling to app theme