i want to implement camera preview app .when I'll test on emulator then it works fine .but when I'll test on real device(eg nexes) then it crash while on rotation change,and also can't able to select image from gallery but it works fine on emulator
my logcat is
02-11 15:11:39.895: W/dalvikvm(8326): threadid=1: thread exiting with uncaught exception
(group=0x41542ba8)
02-11 15:11:39.895: E/AndroidRuntime(8326): FATAL EXCEPTION: main
02-11 15:11:39.895: E/AndroidRuntime(8326): Process: com.photostikers, PID: 8326
02-11 15:11:39.895: E/AndroidRuntime(8326): java.lang.RuntimeException: setParameters failed
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.hardware.Camera.native_setParameters(Native Method)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.hardware.Camera.setParameters(Camera.java:1650)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
com.photostikers.Preview.surfaceChanged(Preview.java:159)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.view.SurfaceView.updateWindow(SurfaceView.java:583)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.view.SurfaceView.access$000(SurfaceView.java:86)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1871)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
02-11 15:11:39.895: E/AndroidRuntime(8326): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.view.Choreographer.doCallbacks(Choreographer.java:574)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.view.Choreographer.doFrame(Choreographer.java:544)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.os.Handler.handleCallback(Handler.java:733)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.os.Handler.dispatchMessage(Handler.java:95)
02-11 15:11:39.895: E/AndroidRuntime(8326): at android.os.Looper.loop(Looper.java:136)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
android.app.ActivityThread.main(ActivityThread.java:5017)
02-11 15:11:39.895: E/AndroidRuntime(8326): at java.lang.reflect.Method.invokeNative(Native
Method)
02-11 15:11:39.895: E/AndroidRuntime(8326): at java.lang.reflect.Method.invoke(Method.java:515)
02-11 15:11:39.895: E/AndroidRuntime(8326): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-11 15:11:39.895: E/AndroidRuntime(8326):at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-11 15:11:39.895: E/AndroidRuntime(8326): at dalvik.system.NativeStart.main(Native Method)
Related
Here's my code. I am trying to set background of a linear layout. But this xml (rowback) is not my main activity content, so gives errors. how can I set some XML from the class which doesn't have that XML in its content?
setContentView(R.layout.activity_quick_search_products);
...
rowb = (LinearLayout)findViewById(R.id.rowback);
...
final Drawable d = getResources().getDrawable(R.drawable.denemebut3);
d.setAlpha(100);
rowb.setBackgroundDrawable(d);
Logcat:
03-30 02:52:50.822: D/AndroidRuntime(14677): Shutting down VM
03-30 02:52:50.822: W/dalvikvm(14677): threadid=1: thread exiting with uncaught exception (group=0x40c841f8)
03-30 02:52:50.822: E/AndroidRuntime(14677): FATAL EXCEPTION: main
03-30 02:52:50.822: E/AndroidRuntime(14677): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vitrinn/com.vitrinn.QuickSearchProducts}: java.lang.NullPointerException
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.ActivityThread.access$600(ActivityThread.java:127)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.os.Handler.dispatchMessage(Handler.java:99)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.os.Looper.loop(Looper.java:137)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.ActivityThread.main(ActivityThread.java:4507)
03-30 02:52:50.822: E/AndroidRuntime(14677): at java.lang.reflect.Method.invokeNative(Native Method)
03-30 02:52:50.822: E/AndroidRuntime(14677): at java.lang.reflect.Method.invoke(Method.java:511)
03-30 02:52:50.822: E/AndroidRuntime(14677): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:978)
03-30 02:52:50.822: E/AndroidRuntime(14677): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
03-30 02:52:50.822: E/AndroidRuntime(14677): at dalvik.system.NativeStart.main(Native Method)
03-30 02:52:50.822: E/AndroidRuntime(14677): Caused by: java.lang.NullPointerException
03-30 02:52:50.822: E/AndroidRuntime(14677): at com.vitrinn.QuickSearchProducts.onCreate(QuickSearchProducts.java:69)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.Activity.performCreate(Activity.java:4469)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
03-30 02:52:50.822: E/AndroidRuntime(14677): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
03-30 02:52:50.822: E/AndroidRuntime(14677): ... 11 more
If R.id.rowback doesn't belong to your main activity xml resource, then you should inflate that resource manually using:
LinearLayout rowb = (LinearLayout) getLayoutInflater().inflate(XML file that contains R.id.rowback, null);
then you can safely do
rowb.setBackgroundDrawable(d);
As an extra, if you have nested elements in rowback then you can invoke:
rowb.findViewById(R.id.Something) safely.
Or if your class is not exteding from any Activity, you can always receive a Context object in its constructor, and then use
LayoutInflater.from(context)
to get a LayoutInflater object so you can inflate any XML resource you need that is not actually in your main content.
Hope this clarifies...
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
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
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.
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) );