Issue with Google Maps Android Api v2 - android

I have been trying to implement a sample application in order to study the working of Google maps API. I have been struck with the configuration itself. I can't seem to run the application.
Here's my code at Github :-
https://github.com/siva54/SampleMapApplication
And here's my logcat :-
02-11 15:09:07.492: I/Process(10080): Sending signal. PID: 10080 SIG: 9
02-11 15:09:17.012: E/dalvikvm(10364): Could not find class 'com.google.android.gms.maps.model.MarkerOptions', referenced from method com.myapp.gasapplication.MainActivity.setUpMap
02-11 15:09:17.012: W/dalvikvm(10364): VFY: unable to resolve new-instance 455 (Lcom/google/android/gms/maps/model/MarkerOptions;) in Lcom/myapp/gasapplication/MainActivity;
02-11 15:09:17.012: D/dalvikvm(10364): VFY: replacing opcode 0x22 at 0x0004
02-11 15:09:17.012: E/dalvikvm(10364): Could not find class 'com.google.android.gms.maps.SupportMapFragment', referenced from method com.myapp.gasapplication.MainActivity.setUpMapIfNeeded
02-11 15:09:17.012: W/dalvikvm(10364): VFY: unable to resolve check-cast 452 (Lcom/google/android/gms/maps/SupportMapFragment;) in Lcom/myapp/gasapplication/MainActivity;
02-11 15:09:17.012: D/dalvikvm(10364): VFY: replacing opcode 0x1f at 0x000e
02-11 15:09:17.012: D/dalvikvm(10364): DexOpt: unable to opt direct call 0x0cd0 at 0x06 in Lcom/myapp/gasapplication/MainActivity;.setUpMap
02-11 15:09:17.022: D/dalvikvm(10364): DexOpt: unable to opt direct call 0x0ccf at 0x0b in Lcom/myapp/gasapplication/MainActivity;.setUpMap
02-11 15:09:17.072: D/AndroidRuntime(10364): Shutting down VM
02-11 15:09:17.072: W/dalvikvm(10364): threadid=1: thread exiting with uncaught exception (group=0x40e02930)
02-11 15:09:17.082: E/AndroidRuntime(10364): FATAL EXCEPTION: main
02-11 15:09:17.082: E/AndroidRuntime(10364): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.gasapplication/com.myapp.gasapplication.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.os.Handler.dispatchMessage(Handler.java:99)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.os.Looper.loop(Looper.java:137)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-11 15:09:17.082: E/AndroidRuntime(10364): at java.lang.reflect.Method.invokeNative(Native Method)
02-11 15:09:17.082: E/AndroidRuntime(10364): at java.lang.reflect.Method.invoke(Method.java:511)
02-11 15:09:17.082: E/AndroidRuntime(10364): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-11 15:09:17.082: E/AndroidRuntime(10364): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-11 15:09:17.082: E/AndroidRuntime(10364): at dalvik.system.NativeStart.main(Native Method)
02-11 15:09:17.082: E/AndroidRuntime(10364): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-11 15:09:17.082: E/AndroidRuntime(10364): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.Activity.setContentView(Activity.java:1881)
02-11 15:09:17.082: E/AndroidRuntime(10364): at com.myapp.gasapplication.MainActivity.onCreate(MainActivity.java:25)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.Activity.performCreate(Activity.java:5104)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-11 15:09:17.082: E/AndroidRuntime(10364): ... 11 more
02-11 15:09:17.082: E/AndroidRuntime(10364): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
02-11 15:09:17.082: E/AndroidRuntime(10364): ... 21 more
02-11 15:09:17.082: E/AndroidRuntime(10364): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: /data/app/com.myapp.gasapplication-1.apk
02-11 15:09:17.082: E/AndroidRuntime(10364): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
02-11 15:09:17.082: E/AndroidRuntime(10364): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-11 15:09:17.082: E/AndroidRuntime(10364): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
02-11 15:09:17.082: E/AndroidRuntime(10364): ... 24 more
02-11 15:10:58.032: E/dalvikvm(10887): Could not find class 'com.google.android.gms.maps.model.MarkerOptions', referenced from method com.myapp.gasapplication.MainActivity.setUpMap
02-11 15:10:58.032: W/dalvikvm(10887): VFY: unable to resolve new-instance 455 (Lcom/google/android/gms/maps/model/MarkerOptions;) in Lcom/myapp/gasapplication/MainActivity;
02-11 15:10:58.032: D/dalvikvm(10887): VFY: replacing opcode 0x22 at 0x0004
02-11 15:10:58.032: E/dalvikvm(10887): Could not find class 'com.google.android.gms.maps.SupportMapFragment', referenced from method com.myapp.gasapplication.MainActivity.setUpMapIfNeeded
02-11 15:10:58.032: W/dalvikvm(10887): VFY: unable to resolve check-cast 452 (Lcom/google/android/gms/maps/SupportMapFragment;) in Lcom/myapp/gasapplication/MainActivity;
02-11 15:10:58.032: D/dalvikvm(10887): VFY: replacing opcode 0x1f at 0x000e
02-11 15:10:58.032: D/dalvikvm(10887): DexOpt: unable to opt direct call 0x0cd0 at 0x06 in Lcom/myapp/gasapplication/MainActivity;.setUpMap
02-11 15:10:58.032: D/dalvikvm(10887): DexOpt: unable to opt direct call 0x0ccf at 0x0b in Lcom/myapp/gasapplication/MainActivity;.setUpMap
02-11 15:10:58.092: D/AndroidRuntime(10887): Shutting down VM
02-11 15:10:58.092: W/dalvikvm(10887): threadid=1: thread exiting with uncaught exception (group=0x40e02930)
02-11 15:10:58.092: E/AndroidRuntime(10887): FATAL EXCEPTION: main
02-11 15:10:58.092: E/AndroidRuntime(10887): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.gasapplication/com.myapp.gasapplication.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.os.Handler.dispatchMessage(Handler.java:99)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.os.Looper.loop(Looper.java:137)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-11 15:10:58.092: E/AndroidRuntime(10887): at java.lang.reflect.Method.invokeNative(Native Method)
02-11 15:10:58.092: E/AndroidRuntime(10887): at java.lang.reflect.Method.invoke(Method.java:511)
02-11 15:10:58.092: E/AndroidRuntime(10887): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-11 15:10:58.092: E/AndroidRuntime(10887): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-11 15:10:58.092: E/AndroidRuntime(10887): at dalvik.system.NativeStart.main(Native Method)
02-11 15:10:58.092: E/AndroidRuntime(10887): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-11 15:10:58.092: E/AndroidRuntime(10887): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.Activity.setContentView(Activity.java:1881)
02-11 15:10:58.092: E/AndroidRuntime(10887): at com.myapp.gasapplication.MainActivity.onCreate(MainActivity.java:25)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.Activity.performCreate(Activity.java:5104)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-11 15:10:58.092: E/AndroidRuntime(10887): ... 11 more
02-11 15:10:58.092: E/AndroidRuntime(10887): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
02-11 15:10:58.092: E/AndroidRuntime(10887): ... 21 more
02-11 15:10:58.092: E/AndroidRuntime(10887): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: /data/app/com.myapp.gasapplication-2.apk
02-11 15:10:58.092: E/AndroidRuntime(10887): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
02-11 15:10:58.092: E/AndroidRuntime(10887): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-11 15:10:58.092: E/AndroidRuntime(10887): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
02-11 15:10:58.092: E/AndroidRuntime(10887): ... 24 more
Would you please help? Thanks in advance.

It looks like it's not finding the Google Maps classes at runtime. Are you running this on a device or an emulator because you can't use Google Maps v2 on an emulator at this time.
If you are running on a device then make sure you have Google Play Services installed. It contains the runtime for Google Maps v2.

Solved my Problem. The issue occurred because even though I i referenced the google play library, The reference is not considered by eclipse and it was shown by a cross mark. I have resolved that with the help of the following stackoverflow post:-
In eclipse, unable to reference an android library project in another android project

Related

Java Build Path and the cleaning up of unwanted debris

In the course of my endevours I added two versions of androidplot to my project. I realised it is causing conflict so I tried removing both to start again and I am now getting
02-11 22:50:10.769: E/AndroidRuntime(20299): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cpdsessions.exercise_app/com.cpdsessions.exercise_app.ActivityLevelView}: android.view.InflateException: Binary XML file line #21: Error inflating class com.androidplot.xy.XYPlot
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.ActivityThread.access$1500(ActivityThread.java:135)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.os.Handler.dispatchMessage(Handler.java:99)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.os.Looper.loop(Looper.java:150)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.ActivityThread.main(ActivityThread.java:4385)
02-11 22:50:10.769: E/AndroidRuntime(20299): at java.lang.reflect.Method.invokeNative(Native Method)
02-11 22:50:10.769: E/AndroidRuntime(20299): at java.lang.reflect.Method.invoke(Method.java:507)
02-11 22:50:10.769: E/AndroidRuntime(20299): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
02-11 22:50:10.769: E/AndroidRuntime(20299): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
02-11 22:50:10.769: E/AndroidRuntime(20299): at dalvik.system.NativeStart.main(Native Method)
02-11 22:50:10.769: E/AndroidRuntime(20299): Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class com.androidplot.xy.XYPlot
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-11 22:50:10.769: E/AndroidRuntime(20299): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:250)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.Activity.setContentView(Activity.java:1742)
02-11 22:50:10.769: E/AndroidRuntime(20299): at com.cpdsessions.exercise_app.ActivityLevelView.onCreate(ActivityLevelView.java:28)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
02-11 22:50:10.769: E/AndroidRuntime(20299): ... 11 more
02-11 22:50:10.769: E/AndroidRuntime(20299): Caused by: java.lang.ClassNotFoundException: com.androidplot.xy.XYPlot in loader dalvik.system.PathClassLoader[/data/app/com.cpdsessions.exercise_app-1.apk]
02-11 22:50:10.769: E/AndroidRuntime(20299): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
02-11 22:50:10.769: E/AndroidRuntime(20299): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
02-11 22:50:10.769: E/AndroidRuntime(20299): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
02-11 22:50:10.769: E/AndroidRuntime(20299): ... 20 more
Can anyone tell me how to clean this up please?
I realised what the issue was here, I still had a androidplot element in my layout, so in fact the project wasn't fully cleaned of the attempt
Thanks

Android emulator ImageView crash

I have add a ImageView and assign a jpg file(a1.jpg), the file is 770Kb. When I run the project, that will Crash and show a lot of error log. I have try another jpg file, the the size is 70KB and run the project, that become no problem. Why? Thanks!
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/Test_string"
android:src="#drawable/a1" />
The error log
02-09 12:47:34.692: D/AndroidRuntime(1023): Shutting down VM
02-09 12:47:34.692: W/dalvikvm(1023): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
02-09 12:47:34.802: E/AndroidRuntime(1023): FATAL EXCEPTION: main
02-09 12:47:34.802: E/AndroidRuntime(1023): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lighter.androidntest4/com.lighter.androidntest4.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.os.Looper.loop(Looper.java:137)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-09 12:47:34.802: E/AndroidRuntime(1023): at java.lang.reflect.Method.invokeNative(Native Method)
02-09 12:47:34.802: E/AndroidRuntime(1023): at java.lang.reflect.Method.invoke(Method.java:511)
02-09 12:47:34.802: E/AndroidRuntime(1023): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-09 12:47:34.802: E/AndroidRuntime(1023): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-09 12:47:34.802: E/AndroidRuntime(1023): at dalvik.system.NativeStart.main(Native Method)
02-09 12:47:34.802: E/AndroidRuntime(1023): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
02-09 12:47:34.802: E/AndroidRuntime(1023): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-09 12:47:34.802: E/AndroidRuntime(1023): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.Activity.setContentView(Activity.java:1881)
02-09 12:47:34.802: E/AndroidRuntime(1023): at com.lighter.androidntest4.MainActivity.onCreate(MainActivity.java:15)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.Activity.performCreate(Activity.java:5104)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-09 12:47:34.802: E/AndroidRuntime(1023): ... 11 more
02-09 12:47:34.802: E/AndroidRuntime(1023): Caused by: java.lang.reflect.InvocationTargetException
02-09 12:47:34.802: E/AndroidRuntime(1023): at java.lang.reflect.Constructor.constructNative(Native Method)
02-09 12:47:34.802: E/AndroidRuntime(1023): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
02-09 12:47:34.802: E/AndroidRuntime(1023): ... 24 more
02-09 12:47:34.802: E/AndroidRuntime(1023): Caused by: java.lang.OutOfMemoryError
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.content.res.Resources.loadDrawable(Resources.java:1965)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.widget.ImageView.<init>(ImageView.java:120)
02-09 12:47:34.802: E/AndroidRuntime(1023): at android.widget.ImageView.<init>(ImageView.java:110)
02-09 12:47:34.802: E/AndroidRuntime(1023): ... 27 more
It's probably because you're trying to load too large file. Even your error says so:
Caused by: java.lang.OutOfMemoryError
770KB image is quite large for android application. You should really think about something smaller.
You can also increase heap size for your emulator in AVD, but still in your situation it's better to use smaller image if you can.
Hmmm... it sounds like your drawable may not be setup correctly. Are you sure about the name etc?
The emulator cannot support that large an image, as shown by java.lang.OutOfMemoryError. You should be able to customise the emulator to allow larger memory by going into the AVD manager (I believe it is Max VM application heap size).
I had the same issue and Piotr Chojnacki was right; it was a image size issue. I assume that this is more of an issue for older devices and the emulator.

How to point to Inner Fragment within XML View

I have two inner fragments in a activity.
Activity is called: MainFragmentActivity (extends FragmentACtivity)
Inside is this:
public static class FeaturedFrag extends ListFragment {
public static class TopFrag extends ListFragment {
How would I identify here?
<fragment
android:id="#+id/featured_frag"
android:layout_width="400dp"
android:layout_height="match_parent"
class="com.---.---.MainFragmentActvity$FeaturedFrag" />
<fragment
android:id="#+id/top_items_frag"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.---.---.MainFragmentActvity$TopItemFrag" />
Changed the XML to the recommendation, LogCat below.
12-05 00:27:35.639: E/AndroidRuntime(1243): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.---.---.MainFragmentActvit$MasterFrag: make sure class name exists, is public, and has an empty constructor that is public
I do have a class with that name, an empty constructor and it is public.
Full LogCat:
12-05 00:37:38.090: E/AndroidRuntime(1384): FATAL EXCEPTION: main
12-05 00:37:38.090: E/AndroidRuntime(1384): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.---.---/com.---.---.master.MainFragmentActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.os.Looper.loop(Looper.java:137)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-05 00:37:38.090: E/AndroidRuntime(1384): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 00:37:38.090: E/AndroidRuntime(1384): at java.lang.reflect.Method.invoke(Method.java:511)
12-05 00:37:38.090: E/AndroidRuntime(1384): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-05 00:37:38.090: E/AndroidRuntime(1384): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-05 00:37:38.090: E/AndroidRuntime(1384): at dalvik.system.NativeStart.main(Native Method)
12-05 00:37:38.090: E/AndroidRuntime(1384): Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-05 00:37:38.090: E/AndroidRuntime(1384): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.Activity.setContentView(Activity.java:1867)
12-05 00:37:38.090: E/AndroidRuntime(1384): at com.---.---.master.MainFragmentActivity.onCreate(MainFragmentActivity.java:85)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.Activity.performCreate(Activity.java:5008)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
12-05 00:37:38.090: E/AndroidRuntime(1384): ... 11 more
12-05 00:37:38.090: E/AndroidRuntime(1384): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.---.---.MainFragmentActivity$MasterFrag: make sure class name exists, is public, and has an empty constructor that is public
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.support.v4.app.Fragment.instantiate(Fragment.java:395)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.support.v4.app.Fragment.instantiate(Fragment.java:363)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:264)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
12-05 00:37:38.090: E/AndroidRuntime(1384): ... 21 more
12-05 00:37:38.090: E/AndroidRuntime(1384): Caused by: java.lang.ClassNotFoundException: com.kickinglettce.rate_this.MainFragmentActivity$MasterFrag
12-05 00:37:38.090: E/AndroidRuntime(1384): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-05 00:37:38.090: E/AndroidRuntime(1384): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-05 00:37:38.090: E/AndroidRuntime(1384): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.support.v4.app.Fragment.instantiate(Fragment.java:385)
12-05 00:37:38.090: E/AndroidRuntime(1384): ... 24 more
Sample code from one of the inner fragments:
public static class MasterFrag extends ListFragment {
// fields
public MasterFrag() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.mastercat, container, false);
}
Proofread all your code. Make sure all class names are the same, are in the same packages, etc. Otherwise Android does not know where anything is.
As for your your original question, the format is class = "package.Activity$Fragment"

Android Inflate Exception occurred

What I have to do for this memory problem ?
02-11 15:40:30.959: E/AndroidRuntime(5108): FATAL EXCEPTION: main
02-11 15:40:30.959: E/AndroidRuntime(5108): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.firewards/com.firewards.Menu}: android.view.InflateException: Binary XML file line #122: Error inflating class <unknown>
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.os.Handler.dispatchMessage(Handler.java:99)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.os.Looper.loop(Looper.java:123)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.ActivityThread.main(ActivityThread.java:3729)
02-11 15:40:30.959: E/AndroidRuntime(5108): at java.lang.reflect.Method.invokeNative(Native Method)
02-11 15:40:30.959: E/AndroidRuntime(5108): at java.lang.reflect.Method.invoke(Method.java:507)
02-11 15:40:30.959: E/AndroidRuntime(5108): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
02-11 15:40:30.959: E/AndroidRuntime(5108): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
02-11 15:40:30.959: E/AndroidRuntime(5108): at dalvik.system.NativeStart.main(Native Method)
02-11 15:40:30.959: E/AndroidRuntime(5108): Caused by: android.view.InflateException: Binary XML file line #122: Error inflating class <unknown>
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
02-11 15:40:30.959: E/AndroidRuntime(5108): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-11 15:40:30.959: E/AndroidRuntime(5108): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.Activity.setContentView(Activity.java:1657)
02-11 15:40:30.959: E/AndroidRuntime(5108): at com.firewards.Menu.onCreate(Menu.java:66)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
02-11 15:40:30.959: E/AndroidRuntime(5108): ... 11 more
02-11 15:40:30.959: E/AndroidRuntime(5108): Caused by: java.lang.reflect.InvocationTargetException
02-11 15:40:30.959: E/AndroidRuntime(5108): at java.lang.reflect.Constructor.constructNative(Native Method)
02-11 15:40:30.959: E/AndroidRuntime(5108): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
02-11 15:40:30.959: E/AndroidRuntime(5108): ... 27 more
02-11 15:40:30.959: E/AndroidRuntime(5108): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.content.res.Resources.loadDrawable(Resources.java:1709)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.View.<init>(View.java:1951)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.widget.ImageView.<init>(ImageView.java:112)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.widget.ImageButton.<init>(ImageButton.java:85)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.widget.ImageButton.<init>(ImageButton.java:81)
02-11 15:40:30.959: E/AndroidRuntime(5108): ... 30 more
Yeah it feels like a memory issues, try releasing some bitmaps prior to accessing that
particular View.
I suggest to check out this video http://dubroy.com/blog/google-io-memory-management-for-android-apps/ which talks about Android memory management.
One thing worth mentioning is that prior to honeycomb, bitmaps were allocated in the native
heap, so watch out for it when profiling memory.
If you're on a device which if Honeycomb or newer, the bitmaps are allocated in the managed
heap.

Create a view by Java code

I used the following code to add a view in a layout
LinearLayout linearLayout_row1_recent_released = (LinearLayout)findViewById(R.id.linearLayout);
View myview = findViewById(R.layout.row);
Button button = myview.findViewById(R.id.mybutton);
linearLayout_row1_recent_released.removeAllViews();
linearLayout_row1_recent_released.addView(myview,LinearLayout.LayoutParams.FILL_PARENT);
Using row.xml i've tried to get a view.
What i get is a FATAL EXCEPTION.
02-11 02:59:04.278: ERROR/AndroidRuntime(780): FATAL EXCEPTION: main
02-11 02:59:04.278: ERROR/AndroidRuntime(780): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aaaaa.ap/com.aaaaaa.ap.AppPlaceMain}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aaaaaa.ap/com.aaaaaa.ap.Store}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aaa.ap/com.aaaaaa.ap.catalog.Home}: java.lang.NullPointerException
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1701)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1717)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:984)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.os.Handler.dispatchMessage(Handler.java:99)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.os.Looper.loop(Looper.java:126)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.main(ActivityThread.java:3900)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at java.lang.reflect.Method.invokeNative(Native Method)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at java.lang.reflect.Method.invoke(Method.java:491)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at dalvik.system.NativeStart.main(Native Method)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aaaaaa.ap/com.aaaaaa.ap.Store}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aaaaaaa.ap/com.aaaaaaa.ap.catalog.Home}: java.lang.NullPointerException
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1701)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1543)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:130)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:342)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:680)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.widget.TabHost.setCurrentTab(TabHost.java:349)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1665)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): ... 11 more
02-11 02:59:04.278: ERROR/AndroidRuntime(780): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aaaaaaa.ap/com.aaaaaa.ap.catalog.Home}: java.lang.NullPointerException
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1701)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1543)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:130)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:342)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at com.aaaaad.ap.Store.onCreate(Store.java:29)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1665)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): ... 20 more
02-11 02:59:04.278: ERROR/AndroidRuntime(780): Caused by: java.lang.NullPointerException
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.view.ViewGroup.addView(ViewGroup.java:2684)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at com.aaaaa.ap.catalog.Home.onCreate(Home.java:51)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1665)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): ... 26 more
Is there any other good way to add views dynamically to a linear layout? What have I done wrong here ?
I am guessing that the view R.layout.row is defined in a separate XML file, and you want to include it here. If that is the case,
findViewById(R.layout.row)
will not work because R.layout.row is not visible in the current activity.
You need to use layout inflater to inflate the view, and then you can add it to the linear layout. The way to do this is
LayoutInflaterinflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View myView = inflater.inflate(R.layout.row, null);
linearLayout_row1_recent_released.addView(myview,
new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT) );
Your call to addView is wrong.
You are calling addView(View, int), but it should be: addView(View, LayoutParams):
linearLayout_row1_recent_released.addView(myview,
new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT) );

Categories

Resources