Android open specific imege in android gallery - android

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

Related

app crashes on android 4.3 [duplicate]

This question already has answers here:
What is a stack trace, and how can I use it to debug my application errors?
(7 answers)
Closed 8 years ago.
I got an issue with an android app I'm trying to develop. When I test it in an emulator with android 4.4.2 (the target sdk version), everything works fine. But when I run the same code in an emulator with the same settings but android 4.3 instead, the app crashes almost immediately with the catlog error below.
Using the android lint in eclipse (right click on project, "Android tools" > "Run lint: check for common error"), I cannot find any code that doesn't correspond with the minSdkVersion (16).
Anyone got suggestions what's going wrong?
Catlog error:
07-24 12:54:14.592: D/AndroidRuntime(1012): Shutting down VM
07-24 12:54:14.592: W/dalvikvm(1012): threadid=1: thread exiting with uncaught exception (group=0x41465700)
07-24 12:54:14.631: E/AndroidRuntime(1012): FATAL EXCEPTION: main
07-24 12:54:14.631: E/AndroidRuntime(1012): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.protime360_basics/com.example.protime360_basics.MainActivity}: java.lang.NullPointerException
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.os.Looper.loop(Looper.java:137)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.main(ActivityThread.java:5103)
07-24 12:54:14.631: E/AndroidRuntime(1012): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 12:54:14.631: E/AndroidRuntime(1012): at java.lang.reflect.Method.invoke(Method.java:525)
07-24 12:54:14.631: E/AndroidRuntime(1012): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
07-24 12:54:14.631: E/AndroidRuntime(1012): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-24 12:54:14.631: E/AndroidRuntime(1012): at dalvik.system.NativeStart.main(Native Method)
07-24 12:54:14.631: E/AndroidRuntime(1012): Caused by: java.lang.NullPointerException
07-24 12:54:14.631: E/AndroidRuntime(1012): at com.example.protime360_basics.MainActivity.loginPopup(MainActivity.java:167)
07-24 12:54:14.631: E/AndroidRuntime(1012): at com.example.protime360_basics.MainActivity.onCreate(MainActivity.java:61)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.Activity.performCreate(Activity.java:5133)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
07-24 12:54:14.631: E/AndroidRuntime(1012): ... 11 more
I found the problem thanks to #codeMagic and #Chris Stratton. Line 167 in my code was
if(!username.equals(null)){
I changed that to
if(username != null && !username.isEmpty()){
=> Problem solved!

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.

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?

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