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.
Related
I've just built my first android app copying the code from this video: https://www.youtube.com/watch?v=gTy13ioTddg&t=594s
The app builds without problems but when I try to run it, it suddenly closes.
That's the message of the debugger:
12/02 12:19:56: Launching 'app' on Pixel_3a_API_30_x86.
Install successfully finished in 519 ms.
$ adb shell am start -n "com.example.pokedex/com.example.pokedex.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.example.pokedex | com.example.pokedex.test
Waiting for application to come online: com.example.pokedex | com.example.pokedex.test
Connecting to com.example.pokedex
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/ActivityThread: Application com.example.pokedex is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/System.out: Debugger has connected
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
Connected to the target VM, address: 'localhost:52033', transport: 'socket'
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/System.out: waiting for debugger to settle...
I/chatty: uid=10153(com.example.pokedex) identical 2 lines
I/System.out: waiting for debugger to settle...
I/System.out: debugger has settled (1475)
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
W/example.pokede: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/example.pokede: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pokedex, PID: 8349
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pokedex/com.example.pokedex.MainActivity}: android.view.InflateException: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Error inflating class android.support.constraint.ConstraintLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: android.view.InflateException: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Error inflating class android.support.constraint.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2 in com.example.pokedex:layout/activity_main: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: android.support.constraint.ConstraintLayout
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at android.view.LayoutInflater.createView(LayoutInflater.java:813)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.inflate(LayoutInflater.java:657)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.pokedex.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/~~ikbXqJo2xtaJUvZzC7gM8Q==/com.example.pokedex-kRHbfAkGOaaI21CGLAjxuQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~ikbXqJo2xtaJUvZzC7gM8Q==/com.example.pokedex-kRHbfAkGOaaI21CGLAjxuQ==/lib/x86, /system/lib, /system_ext/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 26 more
I/Process: Sending signal. PID: 8349 SIG: 9
Disconnected from the target VM, address: 'localhost:52033', transport: 'socket'
This is my Main Activity:
package com.example.pokedex;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private RecyclerView.Adapter adapter;
private RecyclerView.LayoutManager layoutManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView=findViewById(R.id.recycler_view);
adapter=new PokedexAdapter();
layoutManager=new LinearLayoutManager(this);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(layoutManager);
}
}
Activity main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recycler_view"/>
</android.support.constraint.ConstraintLayout>
Pokedex_row:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pokedex_row">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pokedex_row_text_view"/>
</LinearLayout>
Android Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pokedex">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.Pokedex">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I've been trying to solve this problem several days so I would be very thankful if someone can help me!
Have tried you changing your ConstraintLayout to use androidx instead of support
try changing the opening tag of activity_main.xml to be:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
and corresponding closing tag to be
</androidx.constraintlayout.widget.ConstraintLayout>
and then sync your project while connected to the internet.
I think it has problem with ConstraintLayout, can you share your xml files, that way I can help you batter.
I experience this error from time to time and use to solve by doing the following:
First, check if you have ConstraintLayout implementation in your app Gradle config
Then make sure there is no Error(maybe a semantic one) in your layout XML file
If the error persists, consider adding those two files to your question description so that one can easily help
Good Luck!
I'm using the application class , so I had to create the manifest file, as follows:
<application
android.name="com.moonae.android.common.ApplicationClass"
android.icon="#drawble/ic_launcher"
android.largeHeap="true"
....>
<activity..../>
I have to work normally without problems when testing , often the error occurred in the Google Play Store error report.
But the error report is posted on the Android version 4.4 , I even tested at 4.4 operate normally.
If the person experiencing this problem help me.
java.lang.RuntimeException: Unable to instantiate application com.moonae.android.common.ApplicationClass: java.lang.ClassNotFoundException: Didn't find class "com.culturelandnew.android.common.ApplicationClass" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4524)
at android.app.ActivityThread.access$1500(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.moonae.android.common.ApplicationClass" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:993)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
... 11 more
<application
android.name="com.moonae.android.common.ApplicationClass"
android.icon="#drawble/ic_launcher"
android.largeHeap="true"
....>
<activity..../>
is this a typo? i have not seen this before i mean android.name to android:name..btw
quick suggestion, remove your application tag, and use the eclipse gui side to search the application class and reference it.. mostly it references the it without package name included.. like this.. =>
<application
android:name="ApplicationClass"
android:icon="#drawble/ic_launcher"
android:largeHeap="true"
....>
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
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
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" />