Using ActionBarCompat and requestWindowFeature - android

so far i had no bigger problems moving from ActionBarSherlock to ActionBarCompat. On my Nexus 4 it works pretty good. As i began to test on my older Nexus One running 2.3.6 i ran in an problem when i rotate the device. I request an Window feature to show the intermediate progress in the ActionBar:
#Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(android.view.Window.FEATURE_PROGRESS);
requestWindowFeature(android.view.Window.FEATURE_INDETERMINATE_PROGRESS);
setupActionBar(getSupportActionBar());
}
This works pretty good on Jelly Bean.
On 2.3.6 is get this Stack Trace:
08-12 13:34:09.242: E/AndroidRuntime(4602): FATAL EXCEPTION: main
08-12 13:34:09.242: E/AndroidRuntime(4602): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.app.packagename/net.app.fragment.CustomActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
08-12 13:34:09.242: E/AndroidRuntime(4602): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-12 13:34:09.242: E/AndroidRuntime(4602): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-12 13:34:09.242: E/AndroidRuntime(4602): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2832)
08-12 13:34:09.242: E/AndroidRuntime(4602): at android.app.ActivityThread.access$1600(ActivityThread.java:117)
08-12 13:34:09.242: E/AndroidRuntime(4602): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
08-12 13:34:09.242: E/AndroidRuntime(4602): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 13:34:09.242: E/AndroidRuntime(4602): at android.os.Looper.loop(Looper.java:130)
08-12 13:34:09.242: E/AndroidRuntime(4602): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-12 13:34:09.242: E/AndroidRuntime(4602): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 13:34:09.242: E/AndroidRuntime(4602): at java.lang.reflect.Method.invoke(Method.java:507)
08-12 13:34:09.242: E/AndroidRuntime(4602): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-12 13:34:09.242: E/AndroidRuntime(4602): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-12 13:34:09.242: E/AndroidRuntime(4602): at dalvik.system.NativeStart.main(Native Method)
08-12 13:34:09.242: E/AndroidRuntime(4602): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
08-12 13:34:09.242: E/AndroidRuntime(4602): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:181)
08-12 13:34:09.242: E/AndroidRuntime(4602): at android.app.Activity.requestWindowFeature(Activity.java:2729)
08-12 13:34:09.242: E/AndroidRuntime(4602): at net.app.fragment.BaseFragmentActivity.onCreate(BaseFragmentActivity.java:50)
08-12 13:34:09.242: E/AndroidRuntime(4602): at net.app.fragment.CustomActivity.onCreate(CustomActivity.java:55)
08-12 13:34:09.242: E/AndroidRuntime(4602): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-12 13:34:09.242: E/AndroidRuntime(4602): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-12 13:34:09.242: E/AndroidRuntime(4602): ... 12 more
08-12 13:34:12.092: I/Process(4602): Sending signal. PID: 4602 SIG: 9
Anyone knows how to fix this ?
regards

Call supportRequestWindowFeature(Window.FEATURE_...).
See http://android-developers.blogspot.com/2013/08/actionbarcompat-and-io-2013-app-source.html

Use supportRequestWindowFeature(WindowCompat.FEATURE_xxx)
i.e. You also need to use WindowCompat.FEATURE_xxx instead of Window.FEATURE_xxx for backward comptability.

For those, who don't call requestWindowFeature() method but still get the exception, try this workaround:
#Override
protected void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
} catch (Throwable e) {
//dummy workaround
}
setContentView(getLayoutResId());
see https://code.google.com/p/android/issues/detail?id=60841

Error log clearly says 'requestFeature() must be called before adding content'. So you have to call 'super.onCreate(savedInstanceState);' after 'requestWindowFeature' calls. And there is no need to call supportRequestWindowFeature(Window.FEATURE_...) as mentioned above. See the working code below.
#Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
super.onCreate(savedInstanceState);

Related

google app invites(beta) not working in android 2.3.6

Google App Invites(Beta) is not working in android 2.3.6 devices.
I tried out in a 4 devices of different versions & it failed only in 2.3.6.
Kindly point me to resources to resolve this error!
Below is the stacktrace
06-16 08:49:13.939 6396-6396/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.gms/com.google.android.gms.appinvite.AppInviteActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.google.android.gms.appinvite.ui.widget.g.<init>(SourceFile:167)
at com.google.android.gms.appinvite.ui.widget.s.b(SourceFile:80)
at com.google.android.gms.appinvite.ui.widget.d.a(SourceFile:76)
at com.google.android.gms.appinvite.ui.context.h.a(SourceFile:409)
at android.support.v4.app.Fragment.b(SourceFile:1786)
at android.support.v4.app.s.a(SourceFile:953)
at android.support.v4.app.s.a(SourceFile:1136)
at android.support.v4.app.a.run(SourceFile:739)
at android.support.v4.app.s.h(SourceFile:1499)
at android.support.v4.app.l.onStart(SourceFile:548)
at com.google.android.gms.appinvite.AppInviteActivity.onStart(SourceFile:270)

NPE on SupportMapFragment

I successfully built a map-fragment with android maps v2 and it works fine on my smartphone. now i plugged in my tablet and i get a NPE when i try to launch the map-activity. I am totally clueless at the moment; not even knowing what the source of the error may be. can anyone help? thx
OnCreate of map-activity:
FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mySupportMapFragment = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.customer_map_fragment);
mMap = mySupportMapFragment.getMap();
mMap.setMyLocationEnabled(true); <-- line 103 with the NPE
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
customer_map_activity.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="#+id/customer_map_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</FrameLayout>
Logcat:
08-12 11:08:27.449: E/AndroidRuntime(3562): FATAL EXCEPTION: main
08-12 11:08:27.449: E/AndroidRuntime(3562): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cocus.salesapp/com.cocus.salesapp.TestCustomerMapActivity}: java.lang.NullPointerException
08-12 11:08:27.449: E/AndroidRuntime(3562): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
08-12 11:08:27.449: E/AndroidRuntime(3562): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
08-12 11:08:27.449: E/AndroidRuntime(3562): at android.app.ActivityThread.access$600(ActivityThread.java:142)
08-12 11:08:27.449: E/AndroidRuntime(3562): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
08-12 11:08:27.449: E/AndroidRuntime(3562): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 11:08:27.449: E/AndroidRuntime(3562): at android.os.Looper.loop(Looper.java:137)
08-12 11:08:27.449: E/AndroidRuntime(3562): at android.app.ActivityThread.main(ActivityThread.java:4931)
08-12 11:08:27.449: E/AndroidRuntime(3562): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 11:08:27.449: E/AndroidRuntime(3562): at java.lang.reflect.Method.invoke(Method.java:511)
08-12 11:08:27.449: E/AndroidRuntime(3562): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
08-12 11:08:27.449: E/AndroidRuntime(3562): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
08-12 11:08:27.449: E/AndroidRuntime(3562): at dalvik.system.NativeStart.main(Native Method)
08-12 11:08:27.449: E/AndroidRuntime(3562): Caused by: java.lang.NullPointerException
08-12 11:08:27.449: E/AndroidRuntime(3562): at com.fghj.salesapp.TestCustomerMapActivity.onCreate(TestCustomerMapActivity.java:103)
edit:
on phone its running on portrait only. on tablet it is forced to use landscape.
You may learn about the reason via call to GooglePlayServicesUtil.isGooglePlayServicesAvailable.
It will return you an int value which you can compare with ConnectionResult constants.

Android open specific imege in android gallery

i have getted and saved the uri of an image stored in gallery, then I want to open that images
with gallery again.
i'm using this intent...but i get null pointer...
public void vedifoto(View view) {
int i = mViewPager.getCurrentItem();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(foto[i]), "image/*");
startActivity(intent);
}
Error stack:
08-12 09:33:35.669: E/AndroidRuntime(1012): FATAL EXCEPTION: main
08-12 09:33:35.669: E/AndroidRuntime(1012): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.gallery/com.android.camera.ViewImage}: java.lang.NullPointerException
08-12 09:33:35.669: E/AndroidRuntime(1012): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-12 09:33:35.669: E/AndroidRuntime(1012): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-12 09:33:35.669: E/AndroidRuntime(1012): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-12 09:33:35.669: E/AndroidRuntime(1012): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-12 09:33:35.669: E/AndroidRuntime(1012): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 09:33:35.669: E/AndroidRuntime(1012): at android.os.Looper.loop(Looper.java:137)
08-12 09:33:35.669: E/AndroidRuntime(1012): at android.app.ActivityThread.main(ActivityThread.java:5041)
08-12 09:33:35.669: E/AndroidRuntime(1012): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 09:33:35.669: E/AndroidRuntime(1012): at java.lang.reflect.Method.invoke(Method.java:511)
08-12 09:33:35.669: E/AndroidRuntime(1012): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-12 09:33:35.669: E/AndroidRuntime(1012): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-12 09:33:35.669: E/AndroidRuntime(1012): at dalvik.system.NativeStart.main(Native Method)
08-12 09:33:35.669: E/AndroidRuntime(1012): Caused by: java.lang.NullPointerException
08-12 09:33:35.669: E/AndroidRuntime(1012): at com.android.camera.MenuHelper.isWhiteListUri(MenuHelper.java:151)
08-12 09:33:35.669: E/AndroidRuntime(1012): at com.android.camera.ViewImage.onCreate(ViewImage.java:617)
08-12 09:33:35.669: E/AndroidRuntime(1012): at android.app.Activity.performCreate(Activity.java:5104)
08-12 09:33:35.669: E/AndroidRuntime(1012): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-12 09:33:35.669: E/AndroidRuntime(1012): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-12 09:33:35.669: E/AndroidRuntime(1012): ... 11 more
foto is the path of my photo in gallery, i use it as button image, and it work, when user click on it i need to view that image in the gallery.
Use This Codes
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);
You need to specify the correct path...

Android when I call MultiUserChat.getHostedRoom:null pointer exception

today. I am using xmpp Api smack to develop an android application, I want to get the chatting rooms on the openfire server,but when I call the following function:
Collection<HostedRoom> rooms = MultiUserChat.getHostedRooms(ClientConServer.connection,"conference." + ClientConServer.connection.getServiceName());
I get the following error:
08-12 15:53:50.754: E/AndroidRuntime(2897): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.multichat/com.example.multichat.QuestionsList}: java.lang.NullPointerException
08-12 15:53:50.754: E/AndroidRuntime(2897): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-12 15:53:50.754: E/AndroidRuntime(2897): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-12 15:53:50.754: E/AndroidRuntime(2897): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-12 15:53:50.754: E/AndroidRuntime(2897): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-12 15:53:50.754: E/AndroidRuntime(2897): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 15:53:50.754: E/AndroidRuntime(2897): at android.os.Looper.loop(Looper.java:137)
08-12 15:53:50.754: E/AndroidRuntime(2897): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-12 15:53:50.754: E/AndroidRuntime(2897): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 15:53:50.754: E/AndroidRuntime(2897): at java.lang.reflect.Method.invoke(Method.java:525)
08-12 15:53:50.754: E/AndroidRuntime(2897): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-12 15:53:50.754: E/AndroidRuntime(2897): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-12 15:53:50.754: E/AndroidRuntime(2897): at dalvik.system.NativeStart.main(Native Method)
08-12 15:53:50.754: E/AndroidRuntime(2897): Caused by: java.lang.NullPointerException
08-12 15:53:50.754: E/AndroidRuntime(2897): at org.jivesoftware.smackx.muc.MultiUserChat.getHostedRooms(MultiUserChat.java:288)
08-12 15:53:50.754: E/AndroidRuntime(2897): at com.example.multichat.QuestionsList.onCreate(QuestionsList.java:78)
08-12 15:53:50.754: E/AndroidRuntime(2897): at android.app.Activity.performCreate(Activity.java:5133)
08-12 15:53:50.754: E/AndroidRuntime(2897): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-12 15:53:50.754: E/AndroidRuntime(2897): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-12 15:53:50.754: E/AndroidRuntime(2897): ... 11 more
I tried my best to search this problem in google,someone give such advice:
enter link description here
but their methods did not work for me? I need your help!
Put <activity android:name=".QuestionsList"/> in your AndroidManifest.xml (Modify to suit where your activity is)
This is probably an initialization issue.
The java Smack reads at startup META-INF/smack-config.xml and loads the classes listed in there (thereby executing the static blocks in those classes). The Android asmack needs some work-arounds to get a correct initialization.
See also Cannot get list of public rooms from xmpp Server on Android?

Error only in Android versions below 4

I got error on device and emulator with android version 2.3.3, but on device and emulator with Android version 4 - no error...
LogCat say:
08-12 19:07:45.182: E/AndroidRuntime(352): FATAL EXCEPTION: main
08-12 19:07:45.182: E/AndroidRuntime(352): java.lang.NullPointerException
08-12 19:07:45.182: E/AndroidRuntime(352): at android.app.WallpaperManager.setBitmap(WallpaperManager.java:484)
08-12 19:07:45.182: E/AndroidRuntime(352): at com.zznob.lwpchanger.SWpJob$ParseSite.onPostExecute(SWpJob.java:96)
08-12 19:07:45.182: E/AndroidRuntime(352): at com.zznob.lwpchanger.SWpJob$ParseSite.onPostExecute(SWpJob.java:1)
08-12 19:07:45.182: E/AndroidRuntime(352): at android.os.AsyncTask.finish(AsyncTask.java:417)
08-12 19:07:45.182: E/AndroidRuntime(352): at android.os.AsyncTask.access$300(AsyncTask.java:127)
08-12 19:07:45.182: E/AndroidRuntime(352): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
08-12 19:07:45.182: E/AndroidRuntime(352): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 19:07:45.182: E/AndroidRuntime(352): at android.os.Looper.loop(Looper.java:123)
08-12 19:07:45.182: E/AndroidRuntime(352): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-12 19:07:45.182: E/AndroidRuntime(352): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 19:07:45.182: E/AndroidRuntime(352): at java.lang.reflect.Method.invoke(Method.java:507)
08-12 19:07:45.182: E/AndroidRuntime(352): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-12 19:07:45.182: E/AndroidRuntime(352): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-12 19:07:45.182: E/AndroidRuntime(352): at dalvik.system.NativeStart.main(Native Method)
Code with error:
protected void onPostExecute(Bitmap bitmap)
{
if(!isCancelled()){
try{
wallpaperManager.setBitmap(bitmap); <- Error on Android version 2.2-2.3
}
catch(IOException e){
e.printStackTrace();
}
}
super.onPostExecute(bitmap);
}
Build with API version 8... Any idea?
Class full code - http://pastebin.com/iwgYbPfb

Categories

Resources