I am trying to generate a dynamic table problematically It's working properly above API > 11 but its showing some error like this
05-06 12:35:30.303: E/AndroidRuntime(386): FATAL EXCEPTION: main
05-06 12:35:30.303: E/AndroidRuntime(386): java.lang.NoClassDefFoundError: android.app.ActionBar$LayoutParams
05-06 12:35:30.303: E/AndroidRuntime(386): at com.ica.icacounselor.Follow_ups_list_third_level.populateTable(Follow_ups_list_third_level.java:105)
05-06 12:35:30.303: E/AndroidRuntime(386): at com.ica.icacounselor.Follow_ups_list_third_level.onCreate(Follow_ups_list_third_level.java:65)
05-06 12:35:30.303: E/AndroidRuntime(386): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-06 12:35:30.303: E/AndroidRuntime(386): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
05-06 12:35:30.303: E/AndroidRuntime(386): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-06 12:35:30.303: E/AndroidRuntime(386): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-06 12:35:30.303: E/AndroidRuntime(386): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-06 12:35:30.303: E/AndroidRuntime(386): at android.os.Handler.dispatchMessage(Handler.java:99)
05-06 12:35:30.303: E/AndroidRuntime(386): at android.os.Looper.loop(Looper.java:123)
05-06 12:35:30.303: E/AndroidRuntime(386): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-06 12:35:30.303: E/AndroidRuntime(386): at java.lang.reflect.Method.invokeNative(Native Method)
05-06 12:35:30.303: E/AndroidRuntime(386): at java.lang.reflect.Method.invoke(Method.java:507)
05-06 12:35:30.303: E/AndroidRuntime(386): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-06 12:35:30.303: E/AndroidRuntime(386): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-06 12:35:30.303: E/AndroidRuntime(386): at dalvik.system.NativeStart.main(Native Method)
My code follows
//--------------------------------------------------------------------------------------------------
// Creating Table Header
//--------------------------------------------------------------------------------------------------
TableRow followup_tr_head = new TableRow(this);
followup_tr_head.setId(10);
followup_tr_head.setBackgroundResource(R.drawable.list_header);
followup_tr_head.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
final TextView time_name_title = new TextView(this);
time_name_title.setId(20);
time_name_title.setText("Time");
time_name_title.setTextColor(Color.WHITE);
time_name_title.setPadding(5,5,5,5);
followup_tr_head.addView(time_name_title);// add the column to the table row here
time_name_title.setTextSize(12);
final TextView student_name_title = new TextView(this);
student_name_title.setId(20);
student_name_title.setText("Student Name");
student_name_title.setTextColor(Color.WHITE);
student_name_title.setPadding(5,5,5,5);
followup_tr_head.addView(student_name_title);// add the column to the table row here
student_name_title.setTextSize(12);
the ActionBar is presented in API 11. You can't use it in lower API levels.
Yes you can't use ActionBar below API level 11.
To use actionbar in lower api levels use ActionBarSherlock
I had imported import android.app.ActionBar.LayoutParams;
I should import android.widget.TableRow.LayoutParams;
Related
I've created an Android app that works perfectly on my device. I have sent over the APK to someone, and it worked on his device also.
At one point, he wanted to modify something in the app. So I sent him over the complete source code.
Now he is telling me that the source code does not work for him. It compiles fine, but when it runs it from within Eclipse it crashes.
I am 100% sure I have sent him the correct code, that works fine for me. Apparently there is no reason for the crash.
I asked him to send me the logcat errors and I don't seem to find the problem.
Here it is (part of it):
05-06 08:56:10.954: D/dalvikvm(266): GC_FOR_ALLOC freed 2720K, 13% free 27384K/31239K, paused 40ms, total 42ms
05-06 08:56:11.224: D/dalvikvm(266): GC_FOR_ALLOC freed 4048K, 21% free 24747K/31239K, paused 35ms, total 37ms
05-06 08:56:11.224: I/dalvikvm-heap(266): Forcing collection of SoftReferences for 3785616-byte allocation
05-06 08:56:11.284: D/dalvikvm(266): GC_BEFORE_OOM freed 31K, 21% free 24715K/31239K, paused 54ms, total 54ms
05-06 08:56:11.284: E/dalvikvm-heap(266): Out of memory on a 3785616-byte allocation.
05-06 08:56:11.284: I/dalvikvm(266): "main" prio=5 tid=1 RUNNABLE
05-06 08:56:11.284: I/dalvikvm(266): | group="main" sCount=0 dsCount=0 obj=0x2bc9b568 self=0x55569be0
05-06 08:56:11.284: I/dalvikvm(266): | sysTid=266 nice=0 sched=0/0 cgrp=apps handle=716000068
05-06 08:56:11.284: I/dalvikvm(266): | schedstat=( 4120000000 11950000000 1161 ) utm=335 stm=77 core=0
05-06 08:56:11.294: I/dalvikvm(266): at android.graphics.Bitmap.nativeCreate(Native Method)
05-06 08:56:11.294: I/dalvikvm(266): at android.graphics.Bitmap.createBitmap(Bitmap.java:640)
05-06 08:56:11.294: I/dalvikvm(266): at android.graphics.Bitmap.createBitmap(Bitmap.java:620)
05-06 08:56:11.294: I/dalvikvm(266): at com.android.launcher2.Cling.dispatchDraw(Cling.java:208)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.View.buildDrawingCache(View.java:12717)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.View.draw(View.java:13154)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.View.draw(View.java:13461)
05-06 08:56:11.294: I/dalvikvm(266): at android.widget.FrameLayout.draw(FrameLayout.java:467)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.View.draw(View.java:13342)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2806)
05-06 08:56:11.294: I/dalvikvm(266): at com.android.launcher2.DragLayer.dispatchDraw(DragLayer.java:743)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.View.draw(View.java:13461)
05-06 08:56:11.294: I/dalvikvm(266): at android.widget.FrameLayout.draw(FrameLayout.java:467)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.View.draw(View.java:13342)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.View.draw(View.java:13340)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.View.draw(View.java:13340)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.View.draw(View.java:13461)
05-06 08:56:11.294: I/dalvikvm(266): at android.widget.FrameLayout.draw(FrameLayout.java:467)
05-06 08:56:11.294: I/dalvikvm(266): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2183)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2258)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2153)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2021)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1832)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.Choreographer.doFrame(Choreographer.java:525)
05-06 08:56:11.294: I/dalvikvm(266): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
05-06 08:56:11.294: I/dalvikvm(266): at android.os.Handler.handleCallback(Handler.java:615)
05-06 08:56:11.294: I/dalvikvm(266): at android.os.Handler.dispatchMessage(Handler.java:92)
05-06 08:56:11.294: I/dalvikvm(266): at android.os.Looper.loop(Looper.java:137)
05-06 08:56:11.294: I/dalvikvm(266): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-06 08:56:11.294: I/dalvikvm(266): at java.lang.reflect.Method.invokeNative(Native Method)
05-06 08:56:11.294: I/dalvikvm(266): at java.lang.reflect.Method.invoke(Method.java:511)
05-06 08:56:11.294: I/dalvikvm(266): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-06 08:56:11.294: I/dalvikvm(266): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-06 08:56:11.294: I/dalvikvm(266): at dalvik.system.NativeStart.main(Native Method)
05-06 08:56:11.294: D/AndroidRuntime(266): Shutting down VM
05-06 08:56:11.294: W/dalvikvm(266): threadid=1: thread exiting with uncaught exception (group=0x2bc9a300)
05-06 08:56:11.334: E/AndroidRuntime(266): FATAL EXCEPTION: main
05-06 08:56:11.334: E/AndroidRuntime(266): java.lang.OutOfMemoryError
05-06 08:56:11.334: E/AndroidRuntime(266): at android.graphics.Bitmap.nativeCreate(Native Method)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.graphics.Bitmap.createBitmap(Bitmap.java:640)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.graphics.Bitmap.createBitmap(Bitmap.java:620)
05-06 08:56:11.334: E/AndroidRuntime(266): at com.android.launcher2.Cling.dispatchDraw(Cling.java:208)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.View.buildDrawingCache(View.java:12717)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.View.draw(View.java:13154)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.View.draw(View.java:13461)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.widget.FrameLayout.draw(FrameLayout.java:467)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.View.draw(View.java:13342)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2806)
05-06 08:56:11.334: E/AndroidRuntime(266): at com.android.launcher2.DragLayer.dispatchDraw(DragLayer.java:743)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.View.draw(View.java:13461)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.widget.FrameLayout.draw(FrameLayout.java:467)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.View.draw(View.java:13342)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.View.draw(View.java:13340)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.View.draw(View.java:13340)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.View.draw(View.java:13461)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.widget.FrameLayout.draw(FrameLayout.java:467)
05-06 08:56:11.334: E/AndroidRuntime(266): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2183)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2258)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2153)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2021)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1832)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.Choreographer.doFrame(Choreographer.java:525)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.os.Handler.handleCallback(Handler.java:615)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.os.Handler.dispatchMessage(Handler.java:92)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.os.Looper.loop(Looper.java:137)
05-06 08:56:11.334: E/AndroidRuntime(266): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-06 08:56:11.334: E/AndroidRuntime(266): at java.lang.reflect.Method.invokeNative(Native Method)
05-06 08:56:11.334: E/AndroidRuntime(266): at java.lang.reflect.Method.invoke(Method.java:511)
05-06 08:56:11.334: E/AndroidRuntime(266): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-06 08:56:11.334: E/AndroidRuntime(266): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-06 08:56:11.334: E/AndroidRuntime(266): at dalvik.system.NativeStart.main(Native Method)
05-06 08:56:11.346: W/ActivityManager(152): Force finishing activity com.android.launcher/com.android.launcher2.Launcher
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: E/libEGL(36): called unimplemented OpenGL ES API
05-06 08:56:11.449: W/WindowManager(152): Failure taking screenshot for (266x425) to layer 21005
05-06 08:56:11.954: W/ActivityManager(152): Activity pause timeout for ActivityRecord{2c584740 com.android.launcher/com.android.launcher2.Launcher}
05-06 08:56:11.954: I/ActivityManager(152): START {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.launcher/com.android.launcher2.Launcher u=0} from pid 0
05-06 08:56:22.035: W/ActivityManager(152): Activity idle timeout for ActivityRecord{2c57af08 com.android.launcher/com.android.launcher2.Launcher}
The problem you are having is a pretty usual one: your app is running out of memory when it's trying to allocate space for a Bitmap you're using.
There are some techniques you can look up at the Google documentation site for Android programmers. For instance Managing Bitmap Memory.
To avoid the error, this is a pretty good function (again, from Google docs):
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
// Calculate ratios of height and width to requested height and width
final int heightRatio = Math.round((float) height / (float) reqHeight);
final int widthRatio = Math.round((float) width / (float) reqWidth);
// Choose the smallest ratio as inSampleSize value, this will guarantee
// a final image with both dimensions larger than or equal to the
// requested height and width.
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
return inSampleSize;
}
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
What is does is:
Verify the height and width of your Bitmap without actually loading it into memory
Adjust the sampling size so it fits into memory but keeps the required dimensions
Try to increase VM Heap memory in AVD as 64.
In menu select
Window => Android Virtual Device Manager => select avd which you use => click on edit button.
In old Version of ADT.
In new Version of ADT.
When you create new AVD it takes 24 VM Heap as default. but your application need to more memory so, you set it as 64.
I am using iText library for generate new pdf in my app. but my question is how can i use not embedded fonts in program? I'll try this code but its not working for me.
FONTS = "assets/Zapfino.ttf"
BaseFont bf = BaseFont.createFont(FONTS,"CP1251", BaseFont.EMBEDDED);
font = new Font(bf,18);
Paragraph pr = new Paragraph(p12,font);
document.add(pr);
and giv error this
05-06 10:08:31.740: W/System.err(1129): com.itextpdf.text.DocumentException: assets/Zapfino.ttf cannot be embedded due to licensing restrictions.
05-06 10:08:31.740: W/System.err(1129): at com.itextpdf.text.pdf.TrueTypeFont.<init>(TrueTypeFont.java:371)
05-06 10:08:31.740: W/System.err(1129): at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:699)
05-06 10:08:31.740: W/System.err(1129): at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:615)
05-06 10:08:31.740: W/System.err(1129): at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:450)
05-06 10:08:31.740: W/System.err(1129): at com.example.pdfformate.MainActivity.createPdf(MainActivity.java:108)
05-06 10:08:31.740: W/System.err(1129): at com.example.pdfformate.MainActivity.access$0(MainActivity.java:90)
05-06 10:08:31.750: W/System.err(1129): at com.example.pdfformate.MainActivity$1.onClick(MainActivity.java:74)
05-06 10:08:31.750: W/System.err(1129): at android.view.View.performClick(View.java:2485)
05-06 10:08:31.750: W/System.err(1129): at android.view.View$PerformClick.run(View.java:9080)
05-06 10:08:31.750: W/System.err(1129): at android.os.Handler.handleCallback(Handler.java:587)
05-06 10:08:31.750: W/System.err(1129): at android.os.Handler.dispatchMessage(Handler.java:92)
05-06 10:08:31.750: W/System.err(1129): at android.os.Looper.loop(Looper.java:123)
05-06 10:08:31.750: W/System.err(1129): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-06 10:08:31.750: W/System.err(1129): at java.lang.reflect.Method.invokeNative(Native Method)
05-06 10:08:31.750: W/System.err(1129): at java.lang.reflect.Method.invoke(Method.java:507)
05-06 10:08:31.750: W/System.err(1129): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-06 10:08:31.750: W/System.err(1129): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-06 10:08:31.750: W/System.err(1129): at dalvik.system.NativeStart.main(Native Method)
Any help?
I am trying to show a adview in my android application, but it shows an InflateException. This terminates the app and I cannot do anything.
Here is my logcat -
05-06 14:09:09.428: E/AndroidRuntime(928): FATAL EXCEPTION: main
05-06 14:09:09.428: E/AndroidRuntime(928): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kodspider.parkon/com.kodspider.parkon.HomeActivity}: android.view.InflateException: Binary XML file line #18: Error inflating class com.google.ads.AdView
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.os.Handler.dispatchMessage(Handler.java:99)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.os.Looper.loop(Looper.java:137)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.ActivityThread.main(ActivityThread.java:5039)
05-06 14:09:09.428: E/AndroidRuntime(928): at java.lang.reflect.Method.invokeNative(Native Method)
05-06 14:09:09.428: E/AndroidRuntime(928): at java.lang.reflect.Method.invoke(Method.java:511)
05-06 14:09:09.428: E/AndroidRuntime(928): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-06 14:09:09.428: E/AndroidRuntime(928): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-06 14:09:09.428: E/AndroidRuntime(928): at dalvik.system.NativeStart.main(Native Method)
05-06 14:09:09.428: E/AndroidRuntime(928): Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class com.google.ads.AdView
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-06 14:09:09.428: E/AndroidRuntime(928): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.Activity.setContentView(Activity.java:1881)
05-06 14:09:09.428: E/AndroidRuntime(928): at com.kodspider.parkon.HomeActivity.onCreate(HomeActivity.java:31)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.Activity.performCreate(Activity.java:5104)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-06 14:09:09.428: E/AndroidRuntime(928): ... 11 more
05-06 14:09:09.428: E/AndroidRuntime(928): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.ads.AdView" on path: /system/framework/com.google.android.maps.jar:/data/app/com.kodspider.parkon-2.apk
05-06 14:09:09.428: E/AndroidRuntime(928): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
05-06 14:09:09.428: E/AndroidRuntime(928): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-06 14:09:09.428: E/AndroidRuntime(928): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
05-06 14:09:09.428: E/AndroidRuntime(928): ... 22 more
You need to put the admob jar into the libs folder of your project.
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.
I am trying to show one image from web service by consuming it.Well its working
fine.If i test my project with android versions like 2 - 3 versions its working fine.But it is not supporting over 4.0 and above. Why?
How to overcome this issue?
Following is my code,
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(img_url).getContent());
imgvw.setImageBitmap(bitmap);
Logcat
03-23 14:59:17.696: I/System.out(386): Intent { cmp=com.example.png/.tab_cameraActivity }
03-23 14:59:17.696: I/System.out(386): LB 3
03-23 14:59:17.716: D/AndroidRuntime(386): Shutting down VM
03-23 14:59:17.716: W/dalvikvm(386): threadid=1: thread exiting with uncaught exception (group=0x40014760)
03-23 14:59:17.736: E/AndroidRuntime(386): FATAL EXCEPTION: main
03-23 14:59:17.736: E/AndroidRuntime(386): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.png/com.example.png.tab_cameraActivity}: android.os.NetworkOnMainThreadException
03-23 14:59:17.736: E/AndroidRuntime(386): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1577)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:130)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:342)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:680)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.widget.TabHost.setCurrentTab(TabHost.java:349)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:149)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:556)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.view.View.performClick(View.java:3100)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.view.View$PerformClick.run(View.java:11644)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.os.Handler.handleCallback(Handler.java:587)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.os.Handler.dispatchMessage(Handler.java:92)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.os.Looper.loop(Looper.java:126)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.app.ActivityThread.main(ActivityThread.java:3997)
03-23 14:59:17.736: E/AndroidRuntime(386): at java.lang.reflect.Method.invokeNative(Native Method)
03-23 14:59:17.736: E/AndroidRuntime(386): at java.lang.reflect.Method.invoke(Method.java:491)
03-23 14:59:17.736: E/AndroidRuntime(386): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
03-23 14:59:17.736: E/AndroidRuntime(386): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
03-23 14:59:17.736: E/AndroidRuntime(386): at dalvik.system.NativeStart.main(Native Method)
03-23 14:59:17.736: E/AndroidRuntime(386): Caused by: android.os.NetworkOnMainThreadException
03-23 14:59:17.736: E/AndroidRuntime(386): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1077)
03-23 14:59:17.736: E/AndroidRuntime(386): at java.net.InetAddress.lookupHostByName(InetAddress.java:481)
03-23 14:59:17.736: E/AndroidRuntime(386): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:281)
03-23 14:59:17.736: E/AndroidRuntime(386): at java.net.InetAddress.getAllByName(InetAddress.java:249)
03-23 14:59:17.736: E/AndroidRuntime(386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69)
03-23 14:59:17.736: E/AndroidRuntime(386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
03-23 14:59:17.736: E/AndroidRuntime(386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:304)
03-23 14:59:17.736: E/AndroidRuntime(386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
03-23 14:59:17.736: E/AndroidRuntime(386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:292)
03-23 14:59:17.736: E/AndroidRuntime(386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:274)
03-23 14:59:17.736: E/AndroidRuntime(386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:217)
03-23 14:59:17.736: E/AndroidRuntime(386): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76)
03-23 14:59:17.736: E/AndroidRuntime(386): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:153)
03-23 14:59:17.736: E/AndroidRuntime(386): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
03-23 14:59:17.736: E/AndroidRuntime(386): at com.example.png.tab_cameraActivity.getImagesDetails(tab_cameraActivity.java:73)
03-23 14:59:17.736: E/AndroidRuntime(386): at com.example.png.tab_cameraActivity.onCreate(tab_cameraActivity.java:57)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
03-23 14:59:17.736: E/AndroidRuntime(386): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
03-23 14:59:17.736: E/AndroidRuntime(386): ... 18 more
You are getting exception.
NetworkOnMainThreadException: The exception that is thrown when an application attempts to perform a networking operation on its main thread.
so you have to use AsyncTask.
Here is example of AsyncTask.
http://android-developers.blogspot.in/2009/05/painless-threading.html
Chances are that you execute this code inside the UI Thread. This is prohibited in Android HoneyComb and above. You should consider using an AsyncTask or an Android Service to perform this request. Different options are available to help you with that. As a contributor of RoboSpice, I believe this library would help.
I need to replace a Fragment in one Activity with another Fragment, below is the layer file of the Activity:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/home_layout_container">
<fragment android:name="com.foo.FragA"
android:id="#+id/home_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
so by default there is FragA, now I want to replace it with FragB in activity, I did:
public void onRegionClicked(Region region) {
RegionInfoFragment rif = RegionInfoFragment.newInstance(region);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.home_list, rif);
}
But I got exception:
>6:24:40.685: ERROR/AndroidRuntime(9194): Uncaught handler: thread main exiting due to uncaught exception
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.view.ViewGroup.addViewInner(ViewGroup.java:1857)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.view.ViewGroup.addView(ViewGroup.java:1752)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.view.ViewGroup.addView(ViewGroup.java:1709)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.view.ViewGroup.addView(ViewGroup.java:1689)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.support.v4.app.NoSaveStateFrameLayout.wrap(NoSaveStateFrameLayout.java:40)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:743)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:933)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:578)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1219)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:380)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.os.Handler.handleCallback(Handler.java:587)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.os.Handler.dispatchMessage(Handler.java:92)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.os.Looper.loop(Looper.java:123)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at android.app.ActivityThread.main(ActivityThread.java:4363)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at java.lang.reflect.Method.invokeNative(Native Method)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at java.lang.reflect.Method.invoke(Method.java:521)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-06 16:24:40.692: ERROR/AndroidRuntime(9194): at dalvik.system.NativeStart.main(Native Method)
What can I do?
Thanks!
You cannot replace a fragment defined statically in the layout file. You can only replace fragments that you added dynamically via a FragmentTransaction.
Try to commit() at the end of the ft, you need to commit() your changes to let it know.
getFragmentManger()
.beginTransaction
.replace(R.id.frame,Yourfragment.newInstance(),null)
.addtobackstack
.commit();
People always say I am one-liner, so here is one-liner solution for you