Error only in Android versions below 4 - android

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

Related

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...

Using ActionBarCompat and requestWindowFeature

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);

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?

Sources not being found in Eclipse

I'm building an Android app with Eclipse and it all went well until I added a particular KeyEvent code. Once I tried to emulate my app, it crashed and died. I tried to clean it multiple times, but it is not being resolved. Also, when I try to edit the source path, the sources are shown for a split second but disappear. Here are the sources that are not being found:
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2159
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2189
ActivityThread.access$600(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 139
ActivityThread$H.handleMessage(Message) line: 1261
ActivityThread.main(String[]) line: 4894
ZygoteInit$MethodAndArgsCaller.run() line: 784
ZygoteInit.main(String[]) line: 551
NativeStart.main(String[]) line: not available [native method]
How can I make them become able to use? I am so close to my app being ready. This is the only setback in my app.
EDIT: Here's the logcat output:
08-12 10:52:02.359: E/AndroidRuntime(23219): FATAL EXCEPTION: main
08-12 10:52:02.359: E/AndroidRuntime(23219): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mshaw.avanos/com.mshaw.avanos.AvanosActivity}: java.lang.NullPointerException
08-12 10:52:02.359: E/AndroidRuntime(23219): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2075)
08-12 10:52:02.359: E/AndroidRuntime(23219): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2189)
08-12 10:52:02.359: E/AndroidRuntime(23219): at android.app.ActivityThread.access$600(ActivityThread.java:139)
08-12 10:52:02.359: E/AndroidRuntime(23219): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
08-12 10:52:02.359: E/AndroidRuntime(23219): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 10:52:02.359: E/AndroidRuntime(23219): at android.os.Looper.loop(Looper.java:154)
08-12 10:52:02.359: E/AndroidRuntime(23219): at android.app.ActivityThread.main(ActivityThread.java:4894)
08-12 10:52:02.359: E/AndroidRuntime(23219): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 10:52:02.359: E/AndroidRuntime(23219): at java.lang.reflect.Method.invoke(Method.java:511)
08-12 10:52:02.359: E/AndroidRuntime(23219): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-12 10:52:02.359: E/AndroidRuntime(23219): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-12 10:52:02.359: E/AndroidRuntime(23219): at dalvik.system.NativeStart.main(Native Method)
08-12 10:52:02.359: E/AndroidRuntime(23219): Caused by: java.lang.NullPointerException
08-12 10:52:02.359: E/AndroidRuntime(23219): at com.mshaw.avanos.SimpleEula.getPackageInfo(SimpleEula.java:25)
08-12 10:52:02.359: E/AndroidRuntime(23219): at com.mshaw.avanos.SimpleEula.show(SimpleEula.java:33)
08-12 10:52:02.359: E/AndroidRuntime(23219): at com.mshaw.avanos.AvanosActivity.<init>(AvanosActivity.java:36)
08-12 10:52:02.359: E/AndroidRuntime(23219): at java.lang.Class.newInstanceImpl(Native Method)
08-12 10:52:02.359: E/AndroidRuntime(23219): at java.lang.Class.newInstance(Class.java:1319)
08-12 10:52:02.359: E/AndroidRuntime(23219): at android.app.Instrumentation.newActivity(Instrumentation.java:1039)
08-12 10:52:02.359: E/AndroidRuntime(23219): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2066)
08-12 10:52:02.359: E/AndroidRuntime(23219): ... 11 more
Follow these steps
1) Goto your debug view
2) under Breakpoint Tab you will see NullPointerException
3) Right click and uncheck caught.
4) Debug your Project again
Hope this will help you. Thanks

Categories

Resources