illegarlargumentexception in inflating library in popup window - android

I'm working on showing emoji in popup window just like whatsapp from this library. I have created a popup window to show it in main activity. On click of button I made the following code
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
View popUp = getLayoutInflater().inflate(R.layout.popup_item, null);
window = new PopupWindow(getApplicationContext());
window = new PopupWindow(popUp,LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,true);
window.setAnimationStyle(android.R.style.Animation_Activity);
window.showAtLocation(popUp, Gravity.BOTTOM, 0, 0);
window.setFocusable(true);
window.setOutsideTouchable(true);
}
});
The popup_item contain the following
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:emojicon="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context="com.rockerhieu.emojicon.example.MainActivity$PlaceholderFragment" >
<com.rockerhieu.emojicon.EmojiconTextView
android:id="#+id/txtEmojicon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<com.rockerhieu.emojicon.EmojiconEditText
android:id="#+id/editEmojicon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
emojicon:emojiconSize="28sp" />
<fragment
android:id="#+id/emojicons"
android:layout_width="fill_parent"
android:layout_height="220dp"
class="com.rockerhieu.emojicon.EmojiconsFragment" />
</LinearLayout>
it is showing the following error.
01-24 01:07:25.245: E/AndroidRuntime(5420): FATAL EXCEPTION: main
01-24 01:07:25.245: E/AndroidRuntime(5420): android.view.InflateException: Binary XML file line #21: Error inflating class fragment
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-24 01:07:25.245: E/AndroidRuntime(5420): at com.example.popupemoji.MainActivity$1.onClick(MainActivity.java:29)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.View.performClick(View.java:4204)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.View$PerformClick.run(View.java:17355)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.os.Handler.handleCallback(Handler.java:725)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.os.Handler.dispatchMessage(Handler.java:92)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.os.Looper.loop(Looper.java:137)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.app.ActivityThread.main(ActivityThread.java:5041)
01-24 01:07:25.245: E/AndroidRuntime(5420): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 01:07:25.245: E/AndroidRuntime(5420): at java.lang.reflect.Method.invoke(Method.java:511)
01-24 01:07:25.245: E/AndroidRuntime(5420): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-24 01:07:25.245: E/AndroidRuntime(5420): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-24 01:07:25.245: E/AndroidRuntime(5420): at dalvik.system.NativeStart.main(Native Method)
01-24 01:07:25.245: E/AndroidRuntime(5420): Caused by: java.lang.IllegalArgumentException: Binary XML file line #21: Duplicate id 0x7f080000, tag null, or parent id 0x0 with another fragment for com.rockerhieu.emojicon.EmojiconsFragment
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:296)
01-24 01:07:25.245: E/AndroidRuntime(5420): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
I found that the reason for it is the nested fragment. But don't know the solution for it. Please help on this. I really need to solve this. I'm new to android. Thanks.

Related

App not finding resources after locale change in Android

I am working on a project which requires on the fly language changes. I am attempting to set the desired Locale but as soon as I do, the app crashes complaining that it cannot find Resources (things like R.layout.* R.drawable.*)
This is the code I am using to set the new Locale:
String languageToLoad = "es";
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
Edit: added log
E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.flavorburst.mcdonalds/com.flavorburst.mcdonalds.MyActivity}: android.view.InflateException: Binary XML file line #25: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
at android.app.Activity.setContentView(Activity.java:1881)
at com.flavorburst.mcdonalds.MyActivity.onCreate(MyActivity.java:106)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: String array resource ID #0x7f08001e
at android.content.res.Resources.getStringArray(Resources.java:451)
at com.flavorburst.mcdonalds.NavigationDrawerFragment.onCreate(NavigationDrawerFragment.java:91)
at android.app.Fragment.performCreate(Fragment.java:1673)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:854)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1137)
at android.app.Activity.onCreateView(Activity.java:4717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
at android.app.Activity.setContentView(Activity.java:1881)
at com.flavorburst.application.MyActivity.onCreate(MyActivity.java:106)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
This error:
Caused by: android.content.res.Resources$NotFoundException: String array resource ID #0x7f08001e at android.content.res.Resources.getStringArray(Resources.java:451) at com.flavorburst.mcdonalds.NavigationDrawerFragment
refers to a string array that you have defined in one of your XML files, but you forgot to create the string array value in /values/array.xml. For example, in one of your XML files, you may have specified a string array value of "arrayNames", but you forgot to declare it in /values/array.xml like:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="arrayNames"/>
</resources>
So, at runtime, the compiler will complain that it cannot find "arrayNames" in /values/array.xml. Hence, the error you got when you run your app.
Have you tried to clean and rebuild your project? If you are using eclipse got to Project -> Clean. And then build again. If you are using Android Studio and gradle, type the following command line on a terminal:
./gradlew clean
or
use the Build -> Rebuild Project

Retrieving email and other information from facebook login in Android

I want to retrieve users email and other information when he logs in from facebook. I was able to retrieve information when I tested on my device but when I ran the same app on other device it gives me null pointer exception. I have made the application change to public on facebook developers site. Stack trace is attached. I have added the email permission also. Not able to understand why I am able to retrieve in 1 device and not in other device.
Error log:
01-24 11:08:08.696: E/AndroidRuntime(9922): FATAL EXCEPTION: main
01-24 11:08:08.696: E/AndroidRuntime(9922): Process: com.example.logintest, PID: 9922
01-24 11:08:08.696: E/AndroidRuntime(9922): java.lang.NullPointerException
01-24 11:08:08.696: E/AndroidRuntime(9922): at com.example.logintest.MainActivity$2$1.onCompleted(MainActivity.java:237)
01-24 11:08:08.696: E/AndroidRuntime(9922): at com.facebook.Request$1.onCompleted(Request.java:281)
01-24 11:08:08.696: E/AndroidRuntime(9922): at com.facebook.Request$4.run(Request.java:1666)
01-24 11:08:08.696: E/AndroidRuntime(9922): at android.os.Handler.handleCallback(Handler.java:808)
01-24 11:08:08.696: E/AndroidRuntime(9922): at android.os.Handler.dispatchMessage(Handler.java:103)
01-24 11:08:08.696: E/AndroidRuntime(9922): at android.os.Looper.loop(Looper.java:193)
01-24 11:08:08.696: E/AndroidRuntime(9922): at android.app.ActivityThread.main(ActivityThread.java:5299)
01-24 11:08:08.696: E/AndroidRuntime(9922): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 11:08:08.696: E/AndroidRuntime(9922): at java.lang.reflect.Method.invoke(Method.java:515)
01-24 11:08:08.696: E/AndroidRuntime(9922): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
01-24 11:08:08.696: E/AndroidRuntime(9922): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
01-24 11:08:08.696: E/AndroidRuntime(9922): at dalvik.system.NativeStart.main(Native Method)

Rare crash when using fragments with unique id's

I have a very unusual crash that happens maybe once a month or so. There doesn't seem to be any rhyme or reason to it. This is part of a large project, and since I'm not sure where exactly the problem is originating, I'm not sure which portions of code to paste here. So instead I will just describe what I am doing, and I think might be causing the crash.
I have an activity with many nested fragments that I manage with the FragmentManager. Because the nested fragments can be of the same type, I have to give the root view of each fragment a unique ID. The app is crashing when calling super.onResume, and that call is the very first line of my overloaded onResume function (so my code is never given the chance to mess anything up). The reason I think it is crashing due to the unique fragment id's is because I started having this problem after moving to unique id's, and the crash always references a low number resource id.
This error seems to be being thrown in the framework itself, so I'm not sure there is anything I can do about it. Has anyone else come across this, and have the figured out a solution for it? Or alternatively, does anyone know if you can surround super.onResume with a try/catch block? I'm not sure whether the app would be able to recover at that point, and there does not seem to be any way to consistently reproduce this error in order to test it.
01-24 20:55:09.602 E/AndroidRuntime( 8156): FATAL EXCEPTION: main
01-24 20:55:09.602 E/AndroidRuntime( 8156): java.lang.RuntimeException: Unable to resume activity {github.daneren2005.dsub/github.daneren2005.dsub.activity.SubsonicFragmentActivity}: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x2
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3014)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3055)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.ActivityThread.access$600(ActivityThread.java:151)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.os.Looper.loop(Looper.java:155)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.ActivityThread.main(ActivityThread.java:5454)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at java.lang.reflect.Method.invoke(Method.java:511)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at dalvik.system.NativeStart.main(Native Method)
01-24 20:55:09.602 E/AndroidRuntime( 8156): Caused by: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x2
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.content.res.Resources.getResourceName(Resources.java:1666)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:919)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.support.v4.app.FragmentActivity.onResume(FragmentActivity.java:445)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at github.daneren2005.dsub.activity.SubsonicActivity.onResume(SubsonicActivity.java:130)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at github.daneren2005.dsub.activity.SubsonicFragmentActivity.onResume(SubsonicFragmentActivity.java:250)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1266)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.Activity.performResume(Activity.java:5148)
01-24 20:55:09.602 E/AndroidRuntime( 8156): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2997)
01-24 20:55:09.602 E/AndroidRuntime( 8156): ... 12 more
01-24 20:55:09.602 W/ActivityManager( 596): Force finishing activity github.daneren2005.dsub/.activity.SubsonicFragmentActivity
Edit: Added unique id generation. In onCreateView I use rootView.setId(rootId):
public SelectDirectoryFragment() {
super();
rootId = getNewId();
}
#Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
if(bundle != null) {
int tmp = bundle.getInt(Constants.FRAGMENT_ID, -1);
if(tmp > 0) {
rootId = tmp;
}
entries = (List<MusicDirectory.Entry>) bundle.getSerializable(Constants.FRAGMENT_LIST);
restoredInstance = true;
}
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(Constants.FRAGMENT_ID, rootId);
outState.putSerializable(Constants.FRAGMENT_LIST, (Serializable) entries);
}
protected int getNewId() {
for (;;) {
final int result = nextGeneratedId.get();
// aapt-generated IDs have the high byte nonzero; clamp to the range under that.
int newValue = result + 1;
if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
if (nextGeneratedId.compareAndSet(result, newValue)) {
return result;
}
}
}
Check anywhere in your Fragment or Activity that you might be doing a setText() call. It's possible you're trying to set the text to the String.valueOf() value of an integer, but setText() also has an overload which takes an integer resource value (e.g. R.string.my_string). I've seen this crash when I mistakenly did something like the following:
int myCount = doSomeCalculation();
textView.setText(myCount);
This will internally try to resolve myCount as a resource (e.g. getString(myCount)) rather than setting the text to the string value of the myCount variable.
EDIT: Wait, how are you setting this unique ID on your Fragment's root?

Good dynamics fatal exception from sample app

Has anyone encountered this error while trying to use Good Dynamics sample applications from their SDK?
It has me stumped as i have included the what should be all the necessary files
01-24 06:28:21.463: E/AndroidRuntime(1436): FATAL EXCEPTION: main
01-24 06:28:21.463: E/AndroidRuntime(1436): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.good.gd.example.policy/com.good.gd.example.policy.ApplicationPolicy}: java.lang.ClassNotFoundException: Didn't find class "com.good.gd.example.policy.ApplicationPolicy" on path: DexPathList[[zip file "/data/app/com.good.gd.example.policy-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.good.gd.example.policy-2, /vendor/lib, /system/lib]]
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.os.Looper.loop(Looper.java:137)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-24 06:28:21.463: E/AndroidRuntime(1436): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 06:28:21.463: E/AndroidRuntime(1436): at java.lang.reflect.Method.invoke(Method.java:525)
01-24 06:28:21.463: E/AndroidRuntime(1436): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-24 06:28:21.463: E/AndroidRuntime(1436): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-24 06:28:21.463: E/AndroidRuntime(1436): at dalvik.system.NativeStart.main(Native Method)
01-24 06:28:21.463: E/AndroidRuntime(1436): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.good.gd.example.policy.ApplicationPolicy" on path: DexPathList[[zip file "/data/app/com.good.gd.example.policy-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.good.gd.example.policy-2, /vendor/lib, /system/lib]]
01-24 06:28:21.463: E/AndroidRuntime(1436): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
01-24 06:28:21.463: E/AndroidRuntime(1436): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-24 06:28:21.463: E/AndroidRuntime(1436): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
01-24 06:28:21.463: E/AndroidRuntime(1436): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
01-24 06:28:21.463: E/AndroidRuntime(1436): ... 11 more
Yeah, first you need to import project from good sdk folder in extras folder of Android SDK folder, then in gd folder...import the project in workspace, then whenevr you try to run any app on Good Technology, create dependency on that imported project. then you dont get exception. Hope this helps you.

findViewById in activity issue

I'm using ActionBarSherlock and customized style for it:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:textColor="#color/grey"
android:id="#+id/bar_title"
style="#style/Text.Medium">
</TextView>
</LinearLayout>
View mActionBarView = getLayoutInflater().inflate(R.layout.action_bar_custom, null);
getSupportActionBar().setCustomView(mActionBarView);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_HOME);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
In my activity I am overriding setTitle method:
#Override
public void setTitle(CharSequence title) {
TextView txt = (TextView) findViewById(R.id.bar_title);
txt.setText(title);
}
But when in fragment I call getActivity().setTitle(), variable txt in overrided setTitle equals to null.
What's the problem?
Log:
09-06 18:18:21.807: ERROR/AndroidRuntime(953): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.alwx.reader/com.alwx.reader.activity.BookActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:119)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:251)
at com.alwx.reader.activity.BookActivity.onCreate(BookActivity.java:19)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
... 11 more
Caused by: java.lang.NullPointerException
at com.alwx.reader.activity.BookActivity.setTitle(BookActivity.java:28)
at com.alwx.reader.fragment.BookFragment.onCreateView(BookFragment.java:52)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:846)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1160)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
... 22 more
//this will work
TextView txt = (TextView)mActionBarView. findViewById(R.id.bar_title);
txt.setText(title);
//there is no default style as Text.Medium. you are created change it
style="#android:style/TextAppearance.Medium"

Categories

Resources