Hi im practicing on adding logo for app using android Studio. i added simple code as follows .
package com.example.admin.actionbardemo;
import android.app.ActionBar;
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);
ActionBar actionbar= getActionBar();
actionbar.setIcon(R.mipmap.ic_launcher);
actionbar.setDisplayUseLogoEnabled(true);
actionbar.setDisplayShowHomeEnabled(true);
}
}
error:
03-06 02:20:30.272 1381-1381/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.admin.actionbardemo, PID: 1381
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.admin.actionbardemo/com.example.admin.actionbardemo.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.admin.actionbardemo.MainActivity.onCreate(MainActivity.java:21)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
03-06 02:20:30.276 1381-1384/? D/dalvikvm: GC_CONCURRENT freed 205K, 10% free 3023K/3340K, paused 5ms+0ms, total 6ms
Your getActionBar() returns null. I guess you dont have one.
this is androidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin.actionbardemo">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AddingLogo"
android:label="#string/title_activity_adding_logo"
android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
i used android.support.v7.app.ActionBar actionBar=getSupportActionBar();
insted of
ActionBar actionbar= getActionBar();
one more query -my logo is in Drawable folder. which extention need for logo PNG or JPG?
The theme you're using has no ActionBar. You must either change the parent of your AppTheme in styles.xml to a theme with ActionBar or set a toolbar trough setSupportActionBar(...) before calling getSupportActionBar()
Related
Not sure why this is happening, the application shows no errors and I've obtained the key successfully as well but the activity doesn't run!
Here is my MapScreen class:
package com.example.prateekchachra.projectconnecttoastmasters;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
/**
* Created by Prateek Chachra on 5/23/2016.
*/
public class MapScreen extends Activity{
static final LatLng Pos = new LatLng(40, -79);
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
try {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
}
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
googleMap.setMyLocationEnabled(true);
googleMap.setTrafficEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(true);
Marker marker = googleMap.addMarker(new MarkerOptions().position(Pos).title("That is my loc"));
} catch(Exception e){
e.printStackTrace();
}
}
}
Here is my activity_maps.xml file:
<?xml version = "1.0" encoding = "utf-8" ?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.prateekchachra.projectconnecttoastmasters.MapsActivity" />
</RelativeLayout>
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.prateekchachra.projectconnecttoastmasters">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<permission android:name="com.example.prateekchachra.projectconnecttoastmasters.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="ID" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps">
</activity>
<activity android:name=".Events"
android:label="Events List">
</activity>
<activity android:name=".FindSlots"
android:label="Find Slots">
</activity>
<activity android:name=".MapScreen"
android:label="Map Main">
</activity>
<activity android:name=".SplashScreen"
android:label="Splash Screen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Logcat Output:
05-24 03:59:40.867 26851-26851/com.example.prateekchachra.projectconnecttoastmasters E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.prateekchachra.projectconnecttoastmasters/com.example.prateekchachra.projectconnecttoastmasters.MapScreen}: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.access$600(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:281)
at android.app.Activity.setContentView(Activity.java:1881)
at com.example.prateekchachra.projectconnecttoastmasters.MapScreen.onCreate(MapScreen.java:34)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.access$600(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: com.google.android.gms.maps.SupportMapFragment cannot be cast to android.app.Fragment
at android.app.Fragment.instantiate(Fragment.java:585)
at android.app.Fragment.instantiate(Fragment.java:560)
at android.app.Activity.onCreateView(Activity.java:4727)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:281)
at android.app.Activity.setContentView(Activity.java:1881)
at com.example.prateekchachra.projectconnecttoastmasters.MapScreen.onCreate(MapScreen.java:34)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.access$600(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Change your android :name in your XML file
android:name="com.google.android.gms.maps.SupportMapFragment"
Replace with your Fragment package and fragment name like
android:name="com.example.prateekchachra.projectconnecttoastmasters.MapScreen"
I had an old project in Eclipse and I imported it into Android Studio to rebuild it with Material Design.
I done all things...
configured build.gradle and dependencies:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.mhrz.Minesweeper"
minSdkVersion 8
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:cardview-v7:+'
}
and styles:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#1E9618</item>
<item name="colorPrimaryDark">#146310</item>
<item name="colorAccent">#1E9618</item>
</style>
</resources>
and this is Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mhrz.Minesweeper"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".MinesweeperGame"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and also CardView works well.
The problem is that app works correctly with this and give me Holo Design:
public class MinesweeperGame extends Activity {
but I want Material and I get FC on:
public class MinesweeperGame extends AppCompatActivity {
with this log:
01-03 16:29:38.779 12720-12720/com.mhrz.Minesweeper E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mhrz.Minesweeper, PID: 12720
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mhrz.Minesweeper/com.mhrz.Minesweeper.MinesweeperGame}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2219)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5045)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:113)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at com.mhrz.Minesweeper.MinesweeperGame.onCreate(MinesweeperGame.java:55)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2163)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5045)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Where is mistake? How to fix it?
Android system doesn't know that you want to use alternate theme for application (like yours AppTheme) until you define it in application or activity attribute inside AndroidManifest.xml file.
You need to add the android:theme="#style/AppTheme" attribute to your <application> tag in AndroidManifest.xml like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mhrz.Minesweeper"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity android:name=".MinesweeperGame"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I know it is simple but I wasnt able to fix it.Tried many solution from SOF.com but none worked. I am trying to display a title for activity and throws NPE. Using API19 for testing.Below are the codes:
In the activity:
public class DisplayImageActivity extends RootActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().setTitle("Image Preview");
In the Manifest:
<application
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".DisplayImageActivity"
android:label="< app name >"
android:screenOrientation="portrait" >
</activity>
In the style.xml:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
Finally, the logcat says:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.kittu.<> /com.example.kittu.<>.DisplayImageActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2334)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$900(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.kittu.< >.DisplayImageActivity.onCreate(DisplayImageActivity.java:44)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
If you are using the support library, your activity needs to extend it
import android.support.v7.app.AppCompatActivity
public class MainActivity extends AppCompatActivity{
and use getSupportActionBar() instead of getActionBar()
I think you are using AppCompat, then you should use getSupportActionBar() instead of getActionBar().
Change this:
getActionBar().setTitle("Image Preview");
to this:
getSupportActionBar().setTitle("Image Preview");
Hope this helps :)
This question already has answers here:
You need to use a Theme.AppCompat theme (or descendant) with this activity
(63 answers)
Closed 8 years ago.
I am a beginner and have been using treehouse to learn. I am very early in the course and suddenly started getting a crash message when I start the app. I am unsure what is happening. I have posted everything that I know of. Sorry if I missed something or posted too much.
Main:
package com.example.crystalball;
import android.R.string;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
private CrystalBall mCrystalBall = new CrystalBall();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Declare our View variables
final TextView answerLabel = (TextView) findViewById(R.id.textView1);
Button getAnswerButton = (Button) findViewById(R.id.button1);
getAnswerButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
String answer = mCrystalBall.getAnAnswer();
// Update label with dynamic answer
answerLabel.setText(answer);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
CrystalBall:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.crystalball"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<activity
android:name="com.example.crystalball.MainActivity"
android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.crystalball"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<activity
android:name="com.example.crystalball.MainActivity"
android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Logcat:
07-28 01:50:31.530: D/AndroidRuntime(980): Shutting down VM
07-28 01:50:31.530: W/dalvikvm(980): threadid=1: thread exiting with uncaught exception (group=0xb1ae7ba8)
07-28 01:50:31.570: E/AndroidRuntime(980): FATAL EXCEPTION: main
07-28 01:50:31.570: E/AndroidRuntime(980): Process: com.example.crystalball, PID: 980
07-28 01:50:31.570: E/AndroidRuntime(980): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.crystalball/com.example.crystalball.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
07-28 01:50:31.570: E/AndroidRuntime(980): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
07-28 01:50:31.570: E/AndroidRuntime(980): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
07-28 01:50:31.570: E/AndroidRuntime(980): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-28 01:50:31.570: E/AndroidRuntime(980): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-28 01:50:31.570: E/AndroidRuntime(980): at android.os.Handler.dispatchMessage(Handler.java:102)
07-28 01:50:31.570: E/AndroidRuntime(980): at android.os.Looper.loop(Looper.java:136)
07-28 01:50:31.570: E/AndroidRuntime(980): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-28 01:50:31.570: E/AndroidRuntime(980): at java.lang.reflect.Method.invokeNative(Native Method)
07-28 01:50:31.570: E/AndroidRuntime(980): at java.lang.reflect.Method.invoke(Method.java:515)
07-28 01:50:31.570: E/AndroidRuntime(980): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-28 01:50:31.570: E/AndroidRuntime(980): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-28 01:50:31.570: E/AndroidRuntime(980): at dalvik.system.NativeStart.main(Native Method)
07-28 01:50:31.570: E/AndroidRuntime(980): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
07-28 01:50:31.570: E/AndroidRuntime(980): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111)
07-28 01:50:31.570: E/AndroidRuntime(980): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
07-28 01:50:31.570: E/AndroidRuntime(980): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
07-28 01:50:31.570: E/AndroidRuntime(980): at com.example.crystalball.MainActivity.onCreate(MainActivity.java:16)
07-28 01:50:31.570: E/AndroidRuntime(980): at android.app.Activity.performCreate(Activity.java:5231)
07-28 01:50:31.570: E/AndroidRuntime(980): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-28 01:50:31.570: E/AndroidRuntime(980): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
07-28 01:50:31.570: E/AndroidRuntime(980): ... 11 more
07-28 01:50:37.070: I/Process(980): Sending signal. PID: 980 SIG: 9
Your Activity extends ActionBarActivity.
public class MainActivity extends ActionBarActivity
Indicates you are using AppCompat in which case you need to set Theme derieved from Theme.AppCompat to the Activity
or
android:theme="#style/Theme.AppCompat" >
set the theme for the application
To simply add ActionBar Compat your activity or application should use #style/Theme.AppCompat theme in AndroidManifest.xml like this:
<activity
...
android:theme="#style/Theme.AppCompat" />
This will add actionbar in activty(or all activities if you added this theme to application)
i.e. in your manifest file,Change
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
to
android:theme="#style/Theme.AppCompat"
Please change
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
to
android:theme="#android:style/Theme.AppCompat"
I just set up my app with the Google Play library method of adding adds (AdMob). When I run the emulator the add has the error message:
Missing adActivity with android:configChanges in AndroidManifest.xml
I located a fix at:
Missing adActivity with android:configChanges in AndroidManifest.xml
The fix stated to do the following:
"com.google.ads.AdActivity" is declared when using the admob sdk jar in the "libs" folder. >It seems you're using admob via the google play services library so change:
activity android:name="com.google.ads.AdActivity"
To
activity android:name="com.google.android.gms.ads.AdActivity"
Also make sure you add the meta-data tag:
I tried this and the CatLog said to change the meta tag back to:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
My LogCat:
02-23 14:30:27.091: E/AndroidRuntime(1278): FATAL EXCEPTION: main
02-23 14:30:27.091: E/AndroidRuntime(1278): Process: biz.midl.debtcalculator, PID: 1278
02-23 14:30:27.091: E/AndroidRuntime(1278): java.lang.RuntimeException: Unable to start activity ComponentInfo{biz.midl.debtcalculator/biz.midl.debtcalculator.MainActivity}: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.os.Handler.dispatchMessage(Handler.java:102)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.os.Looper.loop(Looper.java:136)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-23 14:30:27.091: E/AndroidRuntime(1278): at java.lang.reflect.Method.invokeNative(Native Method)
02-23 14:30:27.091: E/AndroidRuntime(1278): at java.lang.reflect.Method.invoke(Method.java:515)
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-23 14:30:27.091: E/AndroidRuntime(1278): at dalvik.system.NativeStart.main(Native Method)
02-23 14:30:27.091: E/AndroidRuntime(1278): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4242000 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.google.android.gms.internal.u.a(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.google.android.gms.internal.ag.U(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.google.android.gms.internal.ag.a(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278): at com.google.android.gms.ads.AdView.loadAd(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278): at biz.midl.debtcalculator.MainActivity.onCreate(MainActivity.java:41)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.Activity.performCreate(Activity.java:5231)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-23 14:30:27.091: E/AndroidRuntime(1278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-23 14:30:27.091: E/AndroidRuntime(1278): ... 11 more
Here is my .java:
import java.text.DecimalFormat;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
public class MainActivity extends Activity {
private AdView adView;
double interestRate;
double r, r1;
int nRemaining, nStarting, nDifference, originalBalance,
outstandingBalance, originalTerm;
double minPayment, additionalPayment, newPmt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adView = new AdView(this);
adView.setAdUnitId("xxxxxxxxxxxxxxxxxxxxxxxxxxxx"); //edited out my unitID
adView.setAdSize(AdSize.BANNER);
LinearLayout layout = (LinearLayout) findViewById(R.id.ll);
layout.addView(adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
Here is my Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1" >
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
I also have my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="biz.midl.debtcalculator"
android:versionCode="1"
android:versionName="1" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<activity
android:name="biz.midl.debtcalculator.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.DeviceDefault.Light.NoActionBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="biz.midl.debtcalculator.About"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.DeviceDefault.Light.NoActionBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.ABOUT" />
</intent-filter>
</activity>
</application>
</manifest>
You need to leave the meta-data tag as is:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Additionaly, you need to replace this tag:
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
With this (as suggested in the answer you linked):
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
Since you are using the Google Play Services and not the legacy AdMob SDK you need to replace the name of the activity class from com.google.ads.AdActivity to com.google.android.gms.ads.AdActivity
This may be part of the problem. It seems you are missing....
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
in you AndroidManifest.xml
Make sure you only have the Google Play Services library included and not both Google Play Services and Admob SDK.
It looks like the value of #integer/google_play_services_version is zero. Are the Google Play Services resources being included in your app?
if you are using unity you should use this.
<!-- Google Mobile Ads Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Removing the layout declaration and leaving the programmatic one worked. There were also some unrelated issues causing problems with Eclipse.
From update of play service to version 22 you can go without making above change , I am pasting the code for future reference here
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
in androidmanifest.xml file with having google play service as lib. project instead to use admobsdk.jar file
All you have to do is add this to your AndroidManifest.xml file:
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
it's appear to the screen missing activity with android configchanges in Android manifestxml