There are many answers on the same issues. I tried all of them. Most of are pointing out about changing activity to ActionBarActivity and changing getAction to getSupportAction. But nothing worked for me.
Is there any solution for this issue?
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.drawable.logo_share);
getSupportActionBar().setDisplayUseLogoEnabled(true);
setContentView(R.layout.activity_main);
}
}
exception on setDisplayShowEnabled
Here is the simplest ONE LINE solution.
I think you are getting below
NullPointerException:EXPLANATION:
#. As you are using
getSupportActionBar(), you have to set at least oneAppCompattheme to yourMainActivitythat containsActionBar.For example:
You can use below
themesas they containsActionBar#. As per your
comment, here is yourstyles.xml.SOLUTION:
Just set this
AppThemeto yourMainActivityinAndroidManifest.xml.FYI, I have tried with this and its working perfectly.
OUTPUT:
Hope this will help~