Reading string array from string.xml is throws error in android - java

I try to create a simple listview activity, inwhich the string arrays reads array strings from string.xml which throws error . I have posted the code and log below,
SimpleListViewActivity:
import android.annotation.TargetApi;
import android.app.ListActivity;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class SimpleListViewActivity extends ListActivity {
String[] presidents = getResources().getStringArray(R.array.android_os_flavours);
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ---no need to call this---
// setContentView(R.layout.main);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, presidents));
getActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void onListItemClick(ListView parent, View v, int position, long id) {
Toast.makeText(this, "You have selected " + presidents[position],
Toast.LENGTH_SHORT).show();
}
}
String.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Sethu Vignesh</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="title_activity_simple_list_view">Simple ListView</string>
<string name="title_activity_multi_choice">MultiChoice Listview</string>
<string name="title_activity_single_choice">Single Choice ListView</string>
<string name="title_activity_expandable_list_view">Expandable List View</string>
<string-array name="android_os_flavours">
<item>Android 1.1 Banana Bread(API level 2)</item>
<item>Android 1.5 Cupcake (API level 3)</item>
<item>Android 1.6 Donut (API level 4)</item>
<item>Android 2.0 Eclair (API level 5)</item>
<item>Android 2.0.1 Eclair (API level 6)</item>
<item>Android 2.1 Eclair (API level 7)</item>
<item>Android 2.2–2.2.3 Froyo (API level 8)</item>
<item>Android 2.3–2.3.2 Gingerbread (API level 9)</item>
<item>Android 2.3.3–2.3.7 Gingerbread (API level 10)</item>
<item>Android 3.0 Honeycomb (API level 11)</item>
<item>Android 3.1 Honeycomb (API level 12)</item>
<item>Android 3.2 Honeycomb (API level 13)</item>
<item>Android 4.0–4.0.2 Ice Cream Sandwich (API level 14)</item>
<item>Android 4.0.3–4.0.4 Ice Cream Sandwich (API level 15)</item>
<item>Android 4.1 Jelly Bean (API level 16)</item>
<item>Android 4.2 Jelly Bean (API level 17)</item>
<item>Android 4.3 Jelly Bean (API level 18)</item>
<item>Android 4.4 KitKat (API level 19)</item>
</string-array>
</resources>
Log:
05-09 17:40:09.332: E/AndroidRuntime(1320): FATAL EXCEPTION: main
05-09 17:40:09.332: E/AndroidRuntime(1320): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.sethuvignesh/com.example.sethuvignesh.SimpleListViewActivity}: java.lang.NullPointerException
05-09 17:40:09.332: E/AndroidRuntime(1320): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
05-09 17:40:09.332: E/AndroidRuntime(1320): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
05-09 17:40:09.332: E/AndroidRuntime(1320): at android.app.ActivityThread.access$600(ActivityThread.java:130)
05-09 17:40:09.332: E/AndroidRuntime(1320): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
05-09 17:40:09.332: E/AndroidRuntime(1320): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 17:40:09.332: E/AndroidRuntime(1320): at android.os.Looper.loop(Looper.java:137)
05-09 17:40:09.332: E/AndroidRuntime(1320): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-09 17:40:09.332: E/AndroidRuntime(1320): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 17:40:09.332: E/AndroidRuntime(1320): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 17:40:09.332: E/AndroidRuntime(1320): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-09 17:40:09.332: E/AndroidRuntime(1320): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-09 17:40:09.332: E/AndroidRuntime(1320): at dalvik.system.NativeStart.main(Native Method)
05-09 17:40:09.332: E/AndroidRuntime(1320): Caused by: java.lang.NullPointerException
05-09 17:40:09.332: E/AndroidRuntime(1320): at android.content.ContextWrapper.getResources(ContextWrapper.java:81)
05-09 17:40:09.332: E/AndroidRuntime(1320): at com.example.sethuvignesh.SimpleListViewActivity.<init>(SimpleListViewActivity.java:16)
05-09 17:40:09.332: E/AndroidRuntime(1320): at java.lang.Class.newInstanceImpl(Native Method)
05-09 17:40:09.332: E/AndroidRuntime(1320): at java.lang.Class.newInstance(Class.java:1319)
05-09 17:40:09.332: E/AndroidRuntime(1320): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
05-09 17:40:09.332: E/AndroidRuntime(1320): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
05-09 17:40:09.332: E/AndroidRuntime(1320): ... 11 more
05-09 17:40:09.352: D/dalvikvm(1320): GC_CONCURRENT freed 134K, 3% free 8222K/8391K, paused 13ms+0ms, total 18ms

Move this
String[] presidents = getResources().getStringArray(R.array.android_os_flavours);
inside onCreate
String[] presidents;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
presidents = getResources().getStringArray(R.array.android_os_flavours);
getResources() requires Context. Context is available once activity is created.

I think that this:
String[] presidents = getResources().getStringArray(R.array.android_os_flavours);
should be:
String[] presidents = getResources().getStringArray(R.string.android_os_flavours);
Because it's in the strings.xml file, not in the arrays.xml file

Related

Android app error- unfortunately your app has stopped

I am using eclipse for android app development. When I run my code using emulator, it says unfortunately your app has stopped. In the log cat, it says "Low memory killer". How to resolve this problem? Can anyone answer please..
Here are the stack trace which appear when my app is loading..
09-03 15:54:39.109: E/SysUtils(1892): ApplicationContext is null in ApplicationStatus
09-03 15:54:40.027: E/libEGL(1892): validate_display:255 error 3008 (EGL_BAD_DISPLAY)
09-03 15:54:40.027: E/libEGL(1892): validate_display:255 error 3008 (EGL_BAD_DISPLAY)
09-03 15:54:40.027: E/chromium(1892): [ERROR:gl_surface_egl.cc(327)] No suitable EGL configs found.
09-03 15:54:40.027: E/chromium(1892): [ERROR:gl_surface_android.cc(23)] GLSurfaceEGL::InitializeOneOff failed.
09-03 15:54:40.027: E/chromium(1892): [ERROR:browser_main_loop.cc(698)] GLSurface::InitializeOneOff failed
09-03 15:54:40.396: E/DataReductionProxySettingListener(1892): No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp
09-03 15:54:44.051: A/chromium(1892): [FATAL:gl_surface_android.cc(58)] Check failed: kGLImplementationNone != GetGLImplementation() (0 vs. 0)
09-03 15:54:44.051: A/chromium(1892): --------- beginning of crash
09-03 15:54:44.052: A/libc(1892): Fatal signal 6 (SIGABRT), code -6 in tid 1972 (GpuThread)
09-03 15:57:17.517: E/SysUtils(2115): ApplicationContext is null in ApplicationStatus
09-03 15:57:17.598: E/libEGL(2115): validate_display:255 error 3008 (EGL_BAD_DISPLAY)
09-03 15:57:17.598: E/libEGL(2115): validate_display:255 error 3008 (EGL_BAD_DISPLAY)
09-03 15:57:17.598: E/chromium(2115): [ERROR:gl_surface_egl.cc(327)] No suitable EGL configs found.
09-03 15:57:17.598: E/chromium(2115): [ERROR:gl_surface_android.cc(23)] GLSurfaceEGL::InitializeOneOff failed.
09-03 15:57:17.598: E/chromium(2115): [ERROR:browser_main_loop.cc(698)] GLSurface::InitializeOneOff failed
09-03 15:57:17.674: E/DataReductionProxySettingListener(2115): No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp
09-03 15:57:18.141: A/chromium(2115): [FATAL:gl_surface_android.cc(58)] Check failed: kGLImplementationNone != GetGLImplementation() (0 vs. 0)
09-03 15:57:18.141: A/libc(2115): Fatal signal 6 (SIGABRT), code -6 in tid 2155 (GpuThread)
Main activity file
package com.example.login4;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView ourBrow = (WebView) findViewById(R.id.wvBrowser);
ourBrow.loadUrl("http://www.000webhost.com//");
}
}
XML file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.login4.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/wvBrowser"/>
</RelativeLayout>
This is because of your images have heavy memory. In order to avoid this error, move your images to xxhdpi folder.
In onCreate, the layout is not loaded yet, so
findViewById(R.id.wvBrowser)
returns null. Then in the next line
ourBrow.loadUrl("http://www.000webhost.com//");
will result in a NullPointerException. Solution is to move the code to the onStart method of the Activity:
#Override
protected void onStart() {
super.onStart();
setContentView(R.layout.activity_main);
WebView ourBrow = (WebView) findViewById(R.id.wvBrowser);
ourBrow.loadUrl("http://www.000webhost.com//");
}
Looking at the first error that occurred "No suitable EGL configs found".
I solved this issue by ticking 'Use Host GPU' in the AVD. Also make sure that the Internet permission is added to the AndroidManifest.xml

Unable to call the fragment with imageView in android

Today is my first time to be using the fragments. And I was able to make a simple app that utilizes the fragment, however, there is one problem that I cannot understand or hadn't noticed yet. The problem is the app crashes when I add the fragment with the imageView. Everything works fine when I use simple texts or other widgets. I've set the sample code below.
I'm calling the fragment from Activity1 like this.
android.support.v4.app.FragmentManager fragmentManager2 = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction2 = fragmentManager2.beginTransaction();
TestFragment fragment = new TestFragment();
fragmentTransaction2.add(R.id.fragment_container, fragment,"HELLO");
fragmentTransaction2.commit();
This is the layout that fills the fragment
<LinearLayout
android:id="#+id/fragment_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>
This is the simple Activity2 class that extends the fragment
public class Activity2 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
/** Inflating the layout for this fragment **/
View v = inflater.inflate(R.layout.fragment_class2, null);
return v;
}
}
this is the layout for the class that extends the fragment .
Ps: The imageview in here causes the error, however, the settings in the fragment class may be the problem. I need to display the imageView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/imaew2"
android:src="#drawable/playimage2"
/>
</LinearLayout>
These are the error I get and I'm not sure how these errors mean, however the error is pointing to the Fragment
         
 
 at com.trymeagain.Activity2.onCreateView(Activity2.java:13)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
            at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
Added new Error
05-07 17:56:20.701 3173-3173/com.trymeagain E/art﹕ Throwing OutOfMemoryError "Failed to allocate a 74649612 byte allocation with 1048576 free bytes and 63MB until OOM"
05-07 17:56:20.703 3173-3173/com.trymeagain D/skia﹕ --- allocation failed for scaled bitmap
05-07 17:56:20.704 3173-3173/com.trymeagain D/AndroidRuntime﹕ Shutting down VM
05-07 17:56:20.704 3173-3173/com.trymeagain E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.trymeagain, PID: 3173
android.view.InflateException: Binary XML file line #13: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.trymeagain.PlusOneFragment.onCreateView(Activity2.java:13)
you getting the exception in your imageview where your image playimage2 is too large and the heap memory is not enough to allocate ...
solution-
case1 : if size need to increase on higher resolution device
if playimage2 is possible to patch-then try to reduce the size of the image..you can use tool like photoshop to do so.and then patch the image
case2 : if size need to be constant as written in xml 50dp*50dp
Just try to reduce the size of the image

NullPointerException in Android when declaring a Content Provider

I'm facing a strange issue when declaring a Content Provider in my project. I'm copying the classes and Manifest declaration from another project of my own. It's working OK on my other project.
Here's part of my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.qr"
android:installLocation="auto"
android:versionCode="540"
android:versionName="5.4" >
(...)
<application
android:name=".Application"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:logo="#drawable/ic_launch" >
(...)
<provider
android:name=".provider.HistoryProvider"
android:authorities="com.example.qr.History"
android:exported="true"
android:multiprocess="true"
android:readPermission="com.example.qr.History.read"
android:writePermission="com.example.qr.History.write" />
(...)
</application>
</manifest>
When I run my app, I get this stack trace:
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.app.ActivityThread.installProvider(ActivityThread.java:4783)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4430)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4372)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
This is the whole stack trace. No 'com.example' trace is included. Of course some code in my app is producing this but the actual crash happens in Android.
Because my own classes are not included in the stack trace, I really don't know where to look.
I've run the code in an emulator with Android 4.2 and I've compared it with the source code of that version of Android, so I know the crash is produced in this line of ActivityThread:
4782 ApplicationInfo ai = info.applicationInfo;
4783 if (context.getPackageName().equals(ai.packageName)) {
Here's a link to the source code of this class.
If I don't declare the content provider (i.e. if I remove from my Manifest), the app works perfectly.
I've added some logs to my Application class, as well as the main Activity class. The crash is produced before either is launched.
So, my question is: what in my code can be producing context, context.getPackageName() or info.applicationInfo to be null during installation?
EDIT
When triggering the stack trace in the emulator several times, I only get this between traces:
09-11 23:10:21.250: E/AndroidRuntime(933): at dalvik.system.NativeStart.main(Native Method)
09-11 23:10:21.470: D/dalvikvm(933): GC_CONCURRENT freed 142K, 9% free 2951K/3224K, paused 78ms+3ms, total 225ms
09-11 23:10:44.030: I/Process(933): Sending signal. PID: 933 SIG: 9
09-11 23:10:46.940: D/dalvikvm(947): GC_CONCURRENT freed 164K, 10% free 2711K/2996K, paused 13ms+114ms, total 201ms
09-11 23:10:47.170: I/ActivityThread(947): Pub com.example.qr.History: com.example.qr.provider.HistoryProvider
09-11 23:10:47.170: D/AndroidRuntime(947): Shutting down VM
09-11 23:10:47.170: W/dalvikvm(947): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
09-11 23:10:47.180: E/AndroidRuntime(947): FATAL EXCEPTION: main

Application crashes when is executed using Google maps api v2

I am trying to basically load a map using Google maps api v2 so i can start working on a more complex application.
My problem is that i followed all the instructions in:
https://developers.google.com/maps/documentation/android/
to setup the new settings for the google map api v2 that uses Google play lib.
Everything is set up fine but when i run the application it crashes(myapp stoped working)
I am using intellij so the applications was signed through "build|Generate signed apk" and to get my SHA1 code i used the file that is generated when the Generate signed apk is selected. I created a new project in Google console named MapTest to get the api key and placed that in the manifest as specified.
Now i know that the emulators usually are missing some staff such as the openGL ES so i installed the app on my phone (Galaxy s2) and the application is still crashing.
ps the google play lib was added
Emulator is google api 15 and everything is updated to latest versions.
Any help or input is deeply appreciated.
Bellow i am including my xml files so you can see if there is anything wrong.
main xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
AndroidManifest xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.MapTest"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:targetSdkVersion="15" android:minSdkVersion="8"/>
<application android:label="#string/app_name" android:icon="#drawable/ic_launcher">
<uses-library android:name="com.google.android.maps"/>
<activity android:name="MyActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my api key goes here"/>
</application>
<permission
android:name="com.example.MapTest.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.MapTest.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
</manifest>
MyActivity class
nothing really change tho included just in case
package com.example.MapTest;
import android.app.Activity;
import android.os.Bundle;
import com.google.android.gms.maps.MapFragment;
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
the log of the emulator
01-09 22:16:54.269: DEBUG/AndroidRuntime(1779): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
01-09 22:16:54.269: DEBUG/AndroidRuntime(1779): CheckJNI is ON
01-09 22:16:55.766: DEBUG/AndroidRuntime(1779): Calling main entry com.android.commands.pm.Pm
01-09 22:16:56.059: DEBUG/dalvikvm(1031): GC_EXPLICIT freed 416K, 15% free 11721K/13703K, paused 9ms+19ms
01-09 22:16:56.099: WARN/ActivityManager(1031): No content provider found for permission revoke: file:///data/local/tmp/com.example.MapTest
01-09 22:16:56.139: WARN/ActivityManager(1031): No content provider found for permission revoke: file:///data/local/tmp/com.example.MapTest
01-09 22:16:56.379: INFO/PackageManager(1031): Removing non-system package:com.example.MapTest
01-09 22:16:56.379: INFO/ActivityManager(1031): Force stopping package com.example.MapTest uid=10044
01-09 22:16:56.529: INFO/PackageManager(1031): Package com.example.MapTest codePath changed from /data/app/com.example.MapTest-2.apk to /data/app/com.example.MapTest-1.apk; Retaining data and using new
01-09 22:16:56.529: INFO/PackageManager(1031): Running dexopt on: com.example.MapTest
01-09 22:16:57.781: DEBUG/dalvikvm(1790): DexOpt: load 230ms, verify+opt 493ms
01-09 22:16:57.809: WARN/PackageManager(1031): Code path for pkg : com.example.MapTest changing from /data/app/com.example.MapTest-2.apk to /data/app/com.example.MapTest-1.apk
01-09 22:16:57.809: WARN/PackageManager(1031): Resource path for pkg : com.example.MapTest changing from /data/app/com.example.MapTest-2.apk to /data/app/com.example.MapTest-1.apk
01-09 22:16:57.829: INFO/ActivityManager(1031): Force stopping package com.example.MapTest uid=10044
01-09 22:16:57.939: DEBUG/PackageManager(1031): New package installed in /data/app/com.example.MapTest-1.apk
01-09 22:16:57.949: WARN/PackageManager(1031): Unknown permission android.permission.ADD_SYSTEM_SERVICE in package com.android.phone
01-09 22:16:57.949: WARN/PackageManager(1031): Unknown permission com.android.smspush.WAPPUSH_MANAGER_BIND in package com.android.phone
01-09 22:16:57.959: WARN/PackageManager(1031): Unknown permission com.android.vending.billing.BILLING_ACCOUNT_SERVICE in package com.google.android.gsf.login
01-09 22:16:57.959: WARN/PackageManager(1031): Unknown permission com.android.vending.billing.ADD_CREDIT_CARD in package com.google.android.gsf.login
01-09 22:16:57.959: WARN/PackageManager(1031): Unknown permission com.android.vending.billing.IBillingAccountService.BIND2 in package com.google.android.gsf.login
01-09 22:16:57.959: WARN/PackageManager(1031): Not granting permission android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS to package com.android.browser (protectionLevel=2 flags=0x9be45)
01-09 22:16:57.959: WARN/PackageManager(1031): Not granting permission android.permission.BIND_APPWIDGET to package com.android.widgetpreview (protectionLevel=3 flags=0x28be44)
01-09 22:16:57.989: WARN/PackageManager(1031): Unknown permission com.android.providers.im.permission.READ_ONLY in package com.google.android.apps.maps
01-09 22:16:57.989: WARN/PackageManager(1031): Not granting permission android.permission.DEVICE_POWER to package com.android.deskclock (protectionLevel=2 flags=0x8be45)
01-09 22:16:58.299: DEBUG/dalvikvm(1031): GC_CONCURRENT freed 544K, 15% free 11758K/13703K, paused 9ms+12ms
01-09 22:16:58.489: INFO/ActivityManager(1031): Force stopping package com.example.MapTest uid=10044
01-09 22:16:58.639: DEBUG/dalvikvm(1126): GC_EXPLICIT freed 250K, 7% free 11414K/12231K, paused 5ms+7ms
01-09 22:16:58.869: DEBUG/dalvikvm(1166): GC_EXPLICIT freed 172K, 4% free 9398K/9735K, paused 10ms+9ms
01-09 22:16:59.159: DEBUG/dalvikvm(1031): GC_EXPLICIT freed 191K, 15% free 11704K/13703K, paused 7ms+14ms
01-09 22:16:59.259: DEBUG/PackageManager(1031): generateServicesMap(android.accounts.AccountAuthenticator): 3 services unchanged
01-09 22:16:59.409: DEBUG/PackageManager(1031): generateServicesMap(android.content.SyncAdapter): 5 services unchanged
01-09 22:16:59.431: DEBUG/BackupManagerService(1031): Received broadcast Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:com.example.MapTest flg=0x10000010 (has extras) }
01-09 22:16:59.459: DEBUG/PackageManager(1031): generateServicesMap(android.accounts.AccountAuthenticator): 3 services unchanged
01-09 22:16:59.479: DEBUG/PackageManager(1031): generateServicesMap(android.content.SyncAdapter): 5 services unchanged
01-09 22:16:59.599: DEBUG/BackupManagerService(1031): Received broadcast Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.example.MapTest flg=0x10000010 (has extras) }
01-09 22:16:59.629: VERBOSE/BackupManagerService(1031): updatePackageParticipantsLocked: #1
01-09 22:17:00.642: WARN/RecognitionManagerService(1031): no available voice recognition services found
01-09 22:17:00.889: DEBUG/BackupManagerService(1031): Received broadcast Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:com.example.MapTest flg=0x10000010 (has extras) }
01-09 22:17:00.889: VERBOSE/BackupManagerService(1031): updatePackageParticipantsLocked: #1
01-09 22:17:01.519: DEBUG/dalvikvm(1031): GC_EXPLICIT freed 528K, 14% free 11847K/13703K, paused 7ms+17ms
01-09 22:17:02.069: DEBUG/AndroidRuntime(1779): Shutting down VM
01-09 22:17:02.089: INFO/AndroidRuntime(1779): NOTE: attach of thread 'Binder Thread #3' failed
01-09 22:17:02.089: DEBUG/dalvikvm(1779): GC_CONCURRENT freed 101K, 78% free 456K/2048K, paused 2ms+4ms
01-09 22:17:02.099: DEBUG/jdwp(1779): Got wake-up signal, bailing out of select
01-09 22:17:02.099: DEBUG/dalvikvm(1779): Debugger has detached; object registry had 1 entries
01-09 22:17:02.789: DEBUG/AndroidRuntime(1795): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
01-09 22:17:02.789: DEBUG/AndroidRuntime(1795): CheckJNI is ON
01-09 22:17:03.949: DEBUG/AndroidRuntime(1795): Calling main entry com.android.commands.am.Am
01-09 22:17:03.989: INFO/ActivityManager(1031): START {flg=0x10000000 cmp=com.example.MapTest/.MyActivity} from pid 1795
01-09 22:17:04.029: WARN/WindowManager(1031): Failure taking screenshot for (180x300) to layer 21005
01-09 22:17:04.111: DEBUG/AndroidRuntime(1795): Shutting down VM
01-09 22:17:04.139: DEBUG/dalvikvm(1806): Not late-enabling CheckJNI (already on)
01-09 22:17:04.139: INFO/AndroidRuntime(1795): NOTE: attach of thread 'Binder Thread #3' failed
01-09 22:17:04.159: DEBUG/dalvikvm(1795): GC_CONCURRENT freed 101K, 77% free 486K/2048K, paused 1ms+5ms
01-09 22:17:04.159: DEBUG/jdwp(1795): Got wake-up signal, bailing out of select
01-09 22:17:04.159: DEBUG/dalvikvm(1795): Debugger has detached; object registry had 1 entries
01-09 22:17:04.209: INFO/ActivityManager(1031): Start proc com.example.MapTest for activity com.example.MapTest/.MyActivity: pid=1806 uid=10044 gids={3003, 1015}
01-09 22:17:04.649: WARN/NetworkManagementSocketTagger(1031): setKernelCountSet(10044, 1) failed with errno -2
01-09 22:17:05.269: INFO/Process(1031): Sending signal. PID: 1806 SIG: 3
01-09 22:17:05.309: INFO/dalvikvm(1806): threadid=3: reacting to signal 3
01-09 22:17:05.429: INFO/dalvikvm(1806): Wrote stack traces to '/data/anr/traces.txt'
01-09 22:17:05.599: WARN/dalvikvm(1806): VFY: unable to resolve static field 40 (MapAttrs) in Lcom/google/android/gms/R$styleable;
01-09 22:17:05.599: DEBUG/dalvikvm(1806): VFY: replacing opcode 0x62 at 0x000e
01-09 22:17:05.609: DEBUG/AndroidRuntime(1806): Shutting down VM
01-09 22:17:05.609: WARN/dalvikvm(1806): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
01-09 22:17:05.629: ERROR/AndroidRuntime(1806): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
at android.app.Activity.onCreateView(Activity.java:4242)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
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:251)
at android.app.Activity.setContentView(Activity.java:1835)
at com.example.MapTest.MyActivity.onCreate(MyActivity.java:13)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
01-09 22:17:05.649: WARN/ActivityManager(1031): Force finishing activity com.example.MapTest/.MyActivity
01-09 22:17:05.659: WARN/WindowManager(1031): Failure taking screenshot for (180x300) to layer 21010
01-09 22:17:05.680: INFO/Process(1031): Sending signal. PID: 1806 SIG: 3
01-09 22:17:05.680: INFO/dalvikvm(1806): threadid=3: reacting to signal 3
01-09 22:17:05.699: INFO/dalvikvm(1806): Wrote stack traces to '/data/anr/traces.txt'
01-09 22:17:06.169: WARN/ActivityManager(1031): Activity pause timeout for ActivityRecord{4146dc60 com.example.MapTest/.MyActivity}
01-09 22:17:06.209: INFO/Process(1031): Sending signal. PID: 1806 SIG: 3
01-09 22:17:06.209: INFO/dalvikvm(1806): threadid=3: reacting to signal 3
01-09 22:17:06.229: INFO/dalvikvm(1806): Wrote stack traces to '/data/anr/traces.txt'
01-09 22:17:06.589: WARN/NetworkManagementSocketTagger(1031): setKernelCountSet(10044, 0) failed with errno -2
01-09 22:17:07.899: INFO/Process(1806): Sending signal. PID: 1806 SIG: 9
01-09 22:17:07.919: INFO/ActivityManager(1031): Process com.example.MapTest (pid 1806) has died.
01-09 22:17:08.109: WARN/InputManagerService(1031): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#414b9608
At the moment it is not possible to run Google Android Maps v2 on emulator (see response from Android devs here). You should use real device instead.
However, you can look for updates in this thread - looks like someone managed to create emulator which supports Google Android Maps v2
EDIT:
I can see some problem in your code:
You should extend android.support.v4.app.FragmentActivity, but not regular Activity class.
Also make sure you have added GooglePlayServices project (actually imported entire project) but not just a jar file. If you are using Eclipse, import the library project into your workspace. Click File > Import, select Android > Existing Android Code into Workspace, and browse to the copy of the library project to import it.
I finally fixed the problem. Google has a very bad tutorial. First of all thank you Pavel Dudka for the big help.
i imported google play lib as module and then google play lib as jar then i also added onother jar file android.suport.v4.jar were is can be found as the name is exmaple android\suppor\v4
After those modifications and with the recomentations the map did not work so i added the modified fragment bellow instead of using the one google provited and the map worked like a charm.
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent" />

Error inflating class com.google.ads.AdView

Hello I am new to android dev and admob. I am trying to make a simple test app with a button, a couple pages and admob at the bottom. Everything works fine until I try implementing admob. Here is my code:
HelloAndroid.java:
package com.manny.HelloAndroid;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
private static final int ACTIVITY_CREATE = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView image = (ImageView) findViewById(R.id.test_image);
//image.setScaleType(ImageView.ScaleType.FIT_XY);
}
public void onClick(View v){
Intent i = new Intent(this, HelloPage2.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/test_image"
android:src="#drawable/bak_vert_480x800"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<ImageButton
android:id="#+id/test_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/btn_arrow"
android:layout_marginLeft="100dp"
android:layout_marginTop="200dp"
android:onClick="onClick"
/>
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="b14be806e9ddf1f"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"/>
</RelativeLayout>
hello android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.manny.HelloAndroid"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7"
android:targetSdkVersion="13"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<activity
android:name=".HelloAndroid"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HelloPage2">
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|s mallestScreenSize"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
logcat output:
05-09 13:12:00.859: D/dalvikvm(24278): GC_EXTERNAL_ALLOC freed 51K, 44% free 3054K/5379K, external 2357K/2773K, paused 94ms
05-09 13:12:00.937: D/dalvikvm(24278): GC_EXTERNAL_ALLOC freed 1K, 44% free 3053K/5379K, external 3857K/4816K, paused 31ms
05-09 13:12:01.085: D/AndroidRuntime(24278): Shutting down VM
05-09 13:12:01.085: W/dalvikvm(24278): threadid=1: thread exiting with uncaught exception (group=0x4001e560)
05-09 13:12:01.109: E/AndroidRuntime(24278): FATAL EXCEPTION: main
05-09 13:12:01.109: E/AndroidRuntime(24278): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.manny.HelloAndroid/com.manny.HelloAndroid.HelloAndroid}: android.view.InflateException: Binary XML file line #30: Error inflating class com.google.ads.AdView
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1702)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1722)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.app.ActivityThread.access$1500(ActivityThread.java:124)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:974)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.os.Looper.loop(Looper.java:130)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.app.ActivityThread.main(ActivityThread.java:3821)
05-09 13:12:01.109: E/AndroidRuntime(24278): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 13:12:01.109: E/AndroidRuntime(24278): at java.lang.reflect.Method.invoke(Method.java:507)
05-09 13:12:01.109: E/AndroidRuntime(24278): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-09 13:12:01.109: E/AndroidRuntime(24278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-09 13:12:01.109: E/AndroidRuntime(24278): at dalvik.system.NativeStart.main(Native Method)
05-09 13:12:01.109: E/AndroidRuntime(24278): Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class com.google.ads.AdView
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-09 13:12:01.109: E/AndroidRuntime(24278): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:253)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.app.Activity.setContentView(Activity.java:1716)
05-09 13:12:01.109: E/AndroidRuntime(24278): at com.manny.HelloAndroid.HelloAndroid.onCreate(HelloAndroid.java:17)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1666)
05-09 13:12:01.109: E/AndroidRuntime(24278): ... 11 more
05-09 13:12:01.109: E/AndroidRuntime(24278): Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView in loader dalvik.system.PathClassLoader[/data/app/com.manny.HelloAndroid-2.apk]
05-09 13:12:01.109: E/AndroidRuntime(24278): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-09 13:12:01.109: E/AndroidRuntime(24278): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-09 13:12:01.109: E/AndroidRuntime(24278): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
05-09 13:12:01.109: E/AndroidRuntime(24278): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
05-09 13:12:01.109: E/AndroidRuntime(24278): ... 20 more
05-09 13:12:11.593: I/Process(24278): Sending signal. PID: 24278 SIG: 9
I am using GoogleAdMobAdsSdkAndroid-6.0.0. Again I am very new to this and I have tried using examples off multiple sites but the app continues to crash when it hits a page with admob in it. If someone can help me it would be much appreciated. Thank you. If more code is needed let me know.
Have you recently updated your Android Tools to r17 or higher? If so, you need to create a libs/ folder in your project, and physically put the SDK in the project. Or, in the Java Build Path, you must Order and Export the SDK jar.
Otherwise, the jar doesn't get included when your apk gets compiled, and all hell breaks loose when you run AdMob code at runtime.
NOTE: This applies to any library your project references.
For me it worked like this.
close eclipse
add manually the sdk ad jar file in your project's "libs" folder
open eclipse
refresh your project till the sdk jar appears on libs folder
go to your project's properties > Java Build Path > Library Tab and choose "add Jars" instead of an external one. and select the sdk from the list below.
go to "Order and Export" tab and select again the SDK
click ok AND ITS DONE.
Then just add the proper code in the manifest and the xml.
I was experiencing this, too. The build path didn't seem to work no matter what I did. So I exited Eclipse, created a new libs folder in the workbench package directory. Added the GoogleAdMobAdsSdk-6.0.1.jar to that folder. I DID NOT add the whole SDK, just the jar file. Then restarted Eclipse. I had to refresh the project inspector column to show the changes I made outside of Eclipse. It showed the new libs folder and jar file, but it still didn't work... Then I right clicked on the new libs folder and set it as a SOURCE FOLDER. NOW EVERYTHING WORKS!
Im using Eclipse Version: Indigo Service Release 2
Build id: 20120216-1857
Android Development Tools 18.0.0.v201203301601-306762
It seems that maybe the tools are ahead of the documentation... or some kind of Eclipse bug.... Very aggravating!
I had the same problem and noticed that ordering the export list is also important.
This is mine, this way it works:
What I did - is working for me now - API Level 17
For admob:
- Add adview code to your Layout with appropriate ID
- Add Admob manifest code to your project manifest file
- Add an external GoogleAdmobAdsSDK....jar Jar file to your Library (in Properties\Java Build path)
- Check to choose GoogleAdmobAdsSDK....jar in tab Order and Export
- Restart your ADT
DEGUB = WORKING NOW.
In Android Studio:
1. Paste the Google AdMob SDK into the libs folder for your project
2. Add an entry to dependencies section of your build.gradle for the project pointing at the jar.
3. Rebuild your project
dependencies {
...
compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar', '... other entries...')
}
Note that compile files takes multiple jar entries. If you already have a compile files entry you can just add to it by separating entries with a comma.
The same error appears to me and i solved with few simple steps
You need to remove the appcombat dependency from your project
for removing right click your project->android->remove app combat and make sure you have selected android 4.2.2
and then import the google admob jar into your project.

Categories