Getting resource not found exception in android app - android

I am trying to build an app in AOSP, my development kit has HDPI density, I have double verified it with the following code snippet:
switch (getResources().getDisplayMetrics().densityDpi) {
case DisplayMetrics.DENSITY_LOW:
Log.d(TAG, "\n\n\n\n LDPI \n\n\n\n");
break;
case DisplayMetrics.DENSITY_MEDIUM:
Log.d(TAG, "\n\n\n\n MDPI \n\n\n\n");
break;
case DisplayMetrics.DENSITY_HIGH:
Log.d(TAG, "\n\n\n\n HDPI \n\n\n\n");
// ...
break;
case DisplayMetrics.DENSITY_XHIGH:
Log.d(TAG, "\n\n\n\n XDPI \n\n\n\n");
// ...
break;
}
when I build my application in Android File system,and if I run it, then I am getting following error:
E/AndroidRuntime( 825): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class android.widget.Button
E/AndroidRuntime( 825): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
E/AndroidRuntime( 825): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
E/AndroidRuntime( 825): at android.app.ActivityThread.access$600(ActivityThread.java:123)
E/AndroidRuntime( 825): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
E/AndroidRuntime( 825): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 825): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 825): at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime( 825): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 825): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 825): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime( 825): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime( 825): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 825): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class android.widget.Button
E/AndroidRuntime( 825): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
E/AndroidRuntime( 825): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
E/AndroidRuntime( 825): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
E/AndroidRuntime( 825): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
E/AndroidRuntime( 825): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
E/AndroidRuntime( 825): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
E/AndroidRuntime( 825): at android.view.LayoutInflater.parseInclude(LayoutInflater.java:823)
E/AndroidRuntime( 825): at android.view.LayoutInflater.rInflate(LayoutInflater.java:729)
E/AndroidRuntime( 825): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
E/AndroidRuntime( 825): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
E/AndroidRuntime( 825): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/AndroidRuntime( 825): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime( 825): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/AndroidRuntime( 825): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
E/AndroidRuntime( 825): at android.app.Activity.setContentView(Activity.java:1835)
E/AndroidRuntime( 825): at com.example.MainActivity.onCreate(MainActivity.java:96)
E/AndroidRuntime( 825): at android.app.Activity.performCreate(Activity.java:4465)
E/AndroidRuntime( 825): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime( 825): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
E/AndroidRuntime( 825): ... 11 more
E/AndroidRuntime( 825): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 825): at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 825): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
E/AndroidRuntime( 825): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
E/AndroidRuntime( 825): ... 29 more
E/AndroidRuntime( 825): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f02000d a=-1 r=0x7f02000d}
E/AndroidRuntime( 825): at android.content.res.Resources.loadDrawable(Resources.java:1897)
E/AndroidRuntime( 825): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
E/AndroidRuntime( 825): at android.widget.TextView.<init>(TextView.java:620)
E/AndroidRuntime( 825): at android.widget.Button.<init>(Button.java:108)
E/AndroidRuntime( 825): at android.widget.Button.<init>(Button.java:104)
E/AndroidRuntime( 825): ... 32 more
My all the drawable resources are in drawable-hdpi.
But if I put drawables in all the drawable-* folder then app runs.
But then UI is getting scattered.
Does anybody have idea, what the problem could. Do I have to add any Variable or flag in the Android.mk
=========edit=========
The app works fine if I build with eclipse. And run on the same device.
Therefore issue might be in building app along with AOSP.
========================
Any help would be highly appreciated.
Regards,
Yuvi

So after struggling too long and googling for more then two days, I found the issue. There was no drawable-hdpi folder in apk. I have resolved the issue by adding the LOCAL_AAPT_FLAGS += -c mdpi,hdpi,xhdpi line in Android.mk file.
Those who are struggling with the same kind of problem follow these supper steps:
Check at which line it is giving error:
Binary XML file line #11: Error inflating class android.widget.Button
In my xml file it was:
<Button
android:id="#+id/btn_footer_back"
style="#style/normalButtonStyle"
android:layout_width="wrap_content"
android:layout_height="60px"
android:layout_marginRight="1dp"
android:background="#drawable/button_state_selector"
android:drawableLeft="#drawable/ic_back"
android:drawablePadding="10px"
android:text="#string/back"
android:visibility="gone" />
So, what is the next step now, the log itself tells the story, check the line:
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f02000d a=-1 r=0x7f02000d}
Here r=0x7f02000d is the resource id, that you can find in yourproject/gen/R.java
if you search for 0x7f02000d in R.java then you will able to find which resource is creating the problem, in my case it was R.drawable.ic_back
Hope it helps other to resolve their problems.
Regards,
Yuvi

Your UI is scattered because your files are not matching to appropriate density or resolution while displaying on device. You should use density independent pixels in xml.
And Create Drawable folder and put your files in it. And give reference of the drawable folder.

Related

java.lang.ClassNotFoundException when inflating a view from a jar

I want to replace the rotating icon in progress dialog with my custom icon. The custom icon is part of my own jar placed inside /device//package_name/Custom_View.java. When this class is referenced in my frameworks/base/core/res/res/layout/progress_dialog_holo.xml. I am having this crash
please help me resolve this issue.
E/AndroidRuntime( 699): *** FATAL EXCEPTION IN SYSTEM PROCESS: WindowManagerPolicy
E/AndroidRuntime( 699): android.view.InflateException: Binary XML file line #39: Error inflating class com.iamplus.aware.AwareProgressView
E/AndroidRuntime( 699): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
E/AndroidRuntime( 699): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
E/AndroidRuntime( 699): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
E/AndroidRuntime( 699): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/AndroidRuntime( 699): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime( 699): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/AndroidRuntime( 699): at android.app.ProgressDialog.onCreate(ProgressDialog.java:164)
E/AndroidRuntime( 699): at android.app.Dialog.dispatchOnCreate(Dialog.java:355)
E/AndroidRuntime( 699): at android.app.Dialog.show(Dialog.java:260)
E/AndroidRuntime( 699): at com.android.server.pm.ShutdownThread.beginShutdownSequence(ShutdownThread.java:223)
E/AndroidRuntime( 699): at com.android.server.pm.ShutdownThread.access$000(ShutdownThread.java:57)
E/AndroidRuntime( 699): at com.android.server.pm.ShutdownThread$1.onClick(ShutdownThread.java:140)
E/AndroidRuntime( 699): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:190)
E/AndroidRuntime( 699): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 699): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 699): at com.android.server.wm.WindowManagerService$PolicyThread.run(WindowManagerService.java:882)
E/AndroidRuntime( 699): Caused by: java.lang.ClassNotFoundException: com.iamplus.aware.AwareProgressView
E/AndroidRuntime( 699): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
E/AndroidRuntime( 699): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime( 699): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime( 699): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
E/AndroidRuntime( 699): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
E/AndroidRuntime( 699): ... 15 more
Make sure that you have added the external jar to your project build path.
After that, go to Project -> Properties -> Java Build Path -> Order and Export and mark the checkbox corresponding to your external jar.
Clean and build the project before you run.

How to launch an List fragment activity from Normal activity using On Click of Button

I have created an App with many list fragments in it. It works really fine. I have an main Application in which I want to merge the new list fragment app. I have included activity in Android manifest as well. Below is my Main Activity of ListFragment App, xml have three fragments and nothing else.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ctx1 = getApplicationContext();
}
In my Main App I have several buttons, which launches different Activities on Click.
How do I launch my list fragment using one of the button.
I did use:
Intent listactivity= new Intent(MainActivity.this, TestListFragmentMain.class);
startActivity(listactivity);
But the above code gives me some inflating exceptions :(
Is there a easy way to do this?
Please reply
Trace Logs:
D/dalvikvm( 1478): GC_CONCURRENT freed 140K, 14% free 7493K/8707K, paused 13ms+0ms, total 76ms
D/AndroidRuntime( 1478): Shutting down VM
W/dalvikvm( 1478): threadid=1: thread exiting with uncaught exception (group=0xa631d288)
E/AndroidRuntime( 1478): FATAL EXCEPTION: main
E/AndroidRuntime( 1478): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.droidtv.TvPlayerFunctionalTestApp/org.droidtv.TvPlayerFunctionalTestApp.AndroidListFragmentActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
E/AndroidRuntime( 1478): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
E/AndroidRuntime( 1478): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
E/AndroidRuntime( 1478): at android.app.ActivityThread.access$600(ActivityThread.java:130)
E/AndroidRuntime( 1478): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
E/AndroidRuntime( 1478): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1478): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 1478): at android.app.ActivityThread.main(ActivityThread.java:4745)
E/AndroidRuntime( 1478): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1478): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 1478): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime( 1478): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 1478): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1478): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
E/AndroidRuntime( 1478): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
E/AndroidRuntime( 1478): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
E/AndroidRuntime( 1478): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/AndroidRuntime( 1478): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime( 1478): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/AndroidRuntime( 1478): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
E/AndroidRuntime( 1478): at android.app.Activity.setContentView(Activity.java:1952)
E/AndroidRuntime( 1478): at org.droidtv.TvPlayerFunctionalTestApp.AndroidListFragmentActivity.onCreate(AndroidListFragmentActivity.java:18)
E/AndroidRuntime( 1478): at android.app.Activity.performCreate(Activity.java:5098)
E/AndroidRuntime( 1478): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
E/AndroidRuntime( 1478): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
E/AndroidRuntime( 1478): ... 11 more
E/AndroidRuntime( 1478): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment org.droidtv.VideoFeaturingTestApp.VideoFeaturingMainMenuClass: make sure class name exists, is public, and has an empty constructor that is public
E/AndroidRuntime( 1478): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
E/AndroidRuntime( 1478): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
E/AndroidRuntime( 1478): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
E/AndroidRuntime( 1478): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
I might had missed a step , now when i did the whole thing again everything is working fine. Used normal Intent method to launch new activity

Exception when using custom attributes in layout

I have defined some custom attributes that I want to use throughout my app, which work fine when running through Eclipse, but throws an exception sometimes when the APK has been built and distributed. Below is the stack trace of the exception:
W/dalvikvm( 2521): threadid=1: thread exiting with uncaught exception (group=0x40f44300)
E/AndroidRuntime( 2521): FATAL EXCEPTION: main
E/AndroidRuntime( 2521): android.view.InflateException: Binary XML file line #13: Error inflating class <unknown>
E/AndroidRuntime( 2521): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
E/AndroidRuntime( 2521): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
E/AndroidRuntime( 2521): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
E/AndroidRuntime( 2521): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
E/AndroidRuntime( 2521): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
E/AndroidRuntime( 2521): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
E/AndroidRuntime( 2521): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/AndroidRuntime( 2521): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime( 2521): at com.myapp.android.ui.fragment.CustomDialogFragmentImpl.onCreateView(CustomDialogFragmentImpl.java:74)
E/AndroidRuntime( 2521): at com.myapp.android.ui.fragment.SupportCustomDialogFragment.onCreateView(SupportCustomDialogFragment.java:41)
E/AndroidRuntime( 2521): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
E/AndroidRuntime( 2521): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
E/AndroidRuntime( 2521): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
E/AndroidRuntime( 2521): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
E/AndroidRuntime( 2521): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420)
E/AndroidRuntime( 2521): at android.os.Handler.handleCallback(Handler.java:615)
E/AndroidRuntime( 2521): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 2521): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 2521): at android.app.ActivityThread.main(ActivityThread.java:4745)
E/AndroidRuntime( 2521): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2521): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 2521): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime( 2521): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 2521): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 2521): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 2521): at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 2521): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
E/AndroidRuntime( 2521): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
E/AndroidRuntime( 2521): ... 23 more
E/AndroidRuntime( 2521): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
E/AndroidRuntime( 2521): at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
E/AndroidRuntime( 2521): at android.view.View.<init>(View.java:3342)
E/AndroidRuntime( 2521): at android.view.ViewGroup.<init>(ViewGroup.java:427)
E/AndroidRuntime( 2521): at android.widget.FrameLayout.<init>(FrameLayout.java:101)
E/AndroidRuntime( 2521): at android.widget.FrameLayout.<init>(FrameLayout.java:97)
E/AndroidRuntime( 2521): ... 26 more
Here is the view at line #13:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="12dp"
android:paddingLeft="?attr/listItemPaddingLeft"
android:paddingRight="?attr/listItemPaddingRight" >
Here is my defined attributes:
<declare-styleable name="MyAppTheme">
<attr name="listItemPaddingLeft" format="dimension" />
<attr name="listItemPaddingRight" format="dimension" />
<attr name="listItemHeight" format="dimension" />
<attr name="listHeaderHeight" format="dimension" />
</declare-styleable>
And lastly, here is my theme:
<style name="MyAppTheme" parent="#style/Theme.Sherlock.Light">
<item name="listItemPaddingLeft">22dp</item>
<item name="listItemPaddingRight">22dp</item>
<item name="listItemHeight">43dp</item>
<item name="listHeaderHeight">73dp</item>
</style>
Does anyone see any problems with the way I've defined things, or can offer an explanation as to why this would work when built locally, but not when the APK is signed? My device is the Galaxy Nexus, which worked fine locally and with the signed APK, but the Galaxy S3 does not work with the signed APK (wasn't able to test it locally).
You need to make sure that the currently (used)set theme is one which contains your custom attribute. You can set it in the manifest file or just set it explicitly before inflating the layout:
setTheme(R.style.MyAppTheme)
setContentView(R.layout.MyActivity);

PreferenceActivity getting close the second time i start the app

This is my .java code
public class MainHelp extends PreferenceActivity {
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.help_main);
}
}
and this is the layout
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<Preference
android:title="Commands Documentation"
android:key="#string/commands"/>
<Preference
android:title = "How To Use"
android:key="#string/howToUse"/>
<Preference
android:title="Write Us"
android:key="#string/writeUs"/>
<Preference
android:title="About"
android:key="#string/aboutSuppApp"/>
</PreferenceScreen>
When I run the program the above code works perfectly....But, when i hit home button and try to go to this Activity, I get error saying
E/AndroidRuntime( 495): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 495): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.suppapp/com.suppapp.help.MainHelp}: android.view.InflateException: Binary XML file line #10: Error inflating class prferences
E/AndroidRuntime( 495): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
E/AndroidRuntime( 495): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime( 495): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime( 495): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime( 495): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 495): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 495): at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime( 495): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 495): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 495): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 495): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 495): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 495): Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class prferences
E/AndroidRuntime( 495): at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:441)
E/AndroidRuntime( 495): at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
E/AndroidRuntime( 495): at android.preference.GenericInflater.inflate(GenericInflater.java:326)
E/AndroidRuntime( 495): at android.preference.GenericInflater.inflate(GenericInflater.java:263)
E/AndroidRuntime( 495): at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:254)
E/AndroidRuntime( 495): at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:253)
E/AndroidRuntime( 495): at com.suppapp.help.MainHelp.onCreate(MainHelp.java:19)
E/AndroidRuntime( 495): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 495): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
E/AndroidRuntime( 495): ... 11 more
E/AndroidRuntime( 495): Caused by: java.lang.ClassNotFoundException: android.preference.prferences in loader dalvik.system.PathClassLoader#44c06600
E/AndroidRuntime( 495): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
E/AndroidRuntime( 495): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
E/AndroidRuntime( 495): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
E/AndroidRuntime( 495): at android.preference.GenericInflater.createItem(GenericInflater.java:375)
E/AndroidRuntime( 495): at android.preference.GenericInflater.onCreateItem(GenericInflater.java:417)
E/AndroidRuntime( 495): at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:428)
E/AndroidRuntime( 495): ... 19 more
I tried to link my activity with the other .xml file but getting the same error again!! Even Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class prferences shows the same line number(#10) for other .xml files
i changed the version code(inside manifest file) and re-installed the app...its working fine now.

Android: Handling orientation changes myself - RelativeLayout is getting messed up

In an Android app, I've got an activity that is somewhat complex and may have threads running at certain times which, when finished, will update the UI. As such, having the Activity destroy and create again (due to orientation change) in the middle of one of these threads could lead to the user having to re-try that action, which is bad.
As such, I've decided to handle orientation changes myself by having android:configChanges="orientation|keyboardHidden" in the manifest, and can then override the Activity.onConfigurationChanged(Configuration newConfig) method.
The root layout for this activity is a RelativeLayout.
Currently, I don't actually do anything in onConfigurationChanged() other than call the super().
After an orientation change, the layout is muddled - some elements which are android:layout_above= are either at the bottom of the screen, or floating way above what they should be floating above.
Does anyone have any ideas as to how to fix this?
I'm aware that if I allowed the activity to restart upon an orientation change, it would then use a layout from res/layout-land/, but restarting the activity really seems to be the wrong way to go here.
Edit:
I've tried to setContentView(R.layout.displaymap); in the onConfigurationChanged() method and get the following error:
I/WindowManager( 571): onOrientationChanged, rotation changed to 1
D/StatusBar( 571): updateResources
E/AndroidRuntime( 3813): android.view.InflateException: Binary XML file line #17: Error inflating class java.lang.reflect.Constructor
E/AndroidRuntime( 3813): at android.view.LayoutInflater.createView(LayoutInflater.java:512)
E/AndroidRuntime( 3813): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:564)
E/AndroidRuntime( 3813): at android.view.LayoutInflater.rInflate(LayoutInflater.java:617)
E/AndroidRuntime( 3813): at android.view.LayoutInflater.rInflate(LayoutInflater.java:620)
E/AndroidRuntime( 3813): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
E/AndroidRuntime( 3813): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
E/AndroidRuntime( 3813): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
E/AndroidRuntime( 3813): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
E/AndroidRuntime( 3813): at android.app.Activity.setContentView(Activity.java:1626)
E/AndroidRuntime( 3813): at com.apps.virtualtravel.DisplayMap.onConfigurationChanged(DisplayMap.java:1065)
E/AndroidRuntime( 3813): at android.app.ActivityThread.performConfigurationChanged(ActivityThread.java:3383)
E/AndroidRuntime( 3813): at android.app.ActivityThread.handleConfigurationChanged(ActivityThread.java:3449)
E/AndroidRuntime( 3813): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1762)
E/AndroidRuntime( 3813): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 3813): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 3813): at android.app.ActivityThread.main(ActivityThread.java:3948)
E/AndroidRuntime( 3813): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3813): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 3813): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
E/AndroidRuntime( 3813): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
E/AndroidRuntime( 3813): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 3813): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 3813): at com.google.android.maps.MapView.<init>(MapView.java:237)
E/AndroidRuntime( 3813): at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 3813): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
E/AndroidRuntime( 3813): at android.view.LayoutInflater.createView(LayoutInflater.java:499)
E/AndroidRuntime( 3813): ... 20 more
E/AndroidRuntime( 3813): Caused by: java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity
E/AndroidRuntime( 3813): at com.google.android.maps.MapActivity.setupMapView(MapActivity.java:180)
E/AndroidRuntime( 3813): at com.google.android.maps.MapView.<init>(MapView.java:279)
E/AndroidRuntime( 3813): at com.google.android.maps.MapView.<init>(MapView.java:254)
E/AndroidRuntime( 3813): ... 24 more
You have to create layout for landscape mode if you want to set for landscape and put the layout in layout-land folder with same name which is for portrait and than setContentview(R.layout.name) in onConfigChanged method. this will give the desired UI.other wise you will face issue in RelativeLayout.

Categories

Resources