android - App crashing when trying to save to SD Card -


i'm trying make app averages colour , stuff, have. i've got colour in imageview , have made bitmap, want save on sd card. when press button try , make so, crashes.

i'm hoping give its' own folder when saving, , custom file name. (in ideal world, i'd 1 increases 1 each time, swatch_01.png, swatch_02.png, etc.)

if it's simple might cry little bit.

edit: thank guys, it's fixed. hadn't created javerager_swatches folder , imageview wasn't converting bitmap correctly. had @ after amount of sleep , managed solve it.

package com.colours.javerager; import java.io.file; import java.io.filenotfoundexception; import java.io.fileoutputstream; import java.io.ioexception; import java.io.outputstream; import android.app.actionbar; import android.app.activity; import android.content.intent; import android.graphics.bitmap; import android.graphics.drawable.bitmapdrawable; import android.os.bundle; import android.os.environment; import android.support.v4.app.navutils; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.imageview; import android.widget.textview;  public class averageimageactivity extends activity {   public static final int media_type_image = 1; public textview red; public textview green; public textview blue; public textview hex;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_average_image);     actionbar actionbar = getactionbar();     actionbar.hide(); //hides action bar              final int avgcolour2 = getintent().getextras().getint("totalvalue");     imageview imgtest = (imageview)findviewbyid(r.id.averagecolourgenerated);      imgtest.setbackgroundcolor(avgcolour2);      final int r = getintent().getextras().getint("redvalue");     final int g = getintent().getextras().getint("greenvalue");     final int b = getintent().getextras().getint("bluevalue");     final string hx = getintent().getextras().getstring("hexvalue");      red = (textview)findviewbyid(r.id.redtxt);     red.settext("r: " + r);      green = (textview)findviewbyid(r.id.greentxt);     green.settext("g: " + g);      blue = (textview)findviewbyid(r.id.bluetxt);     blue.settext("b: " + b);      hex = (textview)findviewbyid(r.id.hextxt);     hex.settext("hex: #" + hx);  }  public void clicksavebutton(view v){      final int avgcolour2 = getintent().getextras().getint("totalvalue");      imageview imgtest = (imageview)findviewbyid(r.id.averagecolourgenerated);      imgtest.setbackgroundcolor(avgcolour2);      bitmapdrawable drawable = (bitmapdrawable) imgtest.getdrawable();     final bitmap bmpimg = drawable.getbitmap();         //turns imageview bitmap save      outputstream outstream = null;     file file = new file(environment.getexternalstoragedirectory() + "/javerager_swatches/", "swatch.png");     try {         outstream = new fileoutputstream(file);             bmpimg.compress(bitmap.compressformat.png, 100, outstream);             outstream.flush();             outstream.close();    } catch (filenotfoundexception e) {     } catch (ioexception e) {    }  }  public void clickhomebutton(view v){     intent intent = new intent(this, menuscreenactivity.class);     startactivity(intent);   } 

edit: there's lot of logcat stuff , it's red , angry ;~;

04-19 23:30:54.308: e/androidruntime(1184): fatal exception: main

04-19 23:30:54.308: e/androidruntime(1184): process: com.colours.javerager, pid: 1184

04-19 23:30:54.308: e/androidruntime(1184): java.lang.illegalstateexception: not execute method of activity

04-19 23:30:54.308: e/androidruntime(1184): @ android.view.view$1.onclick(view.java:3814)

04-19 23:30:54.308: e/androidruntime(1184): @ android.view.view.performclick(view.java:4424)

04-19 23:30:54.308: e/androidruntime(1184): @ android.view.view$performclick.run(view.java:18383)

04-19 23:30:54.308: e/androidruntime(1184): @ android.os.handler.handlecallback(handler.java:733)

04-19 23:30:54.308: e/androidruntime(1184): @ android.os.handler.dispatchmessage(handler.java:95)

04-19 23:30:54.308: e/androidruntime(1184): @ android.os.looper.loop(looper.java:137)

04-19 23:30:54.308: e/androidruntime(1184): @ android.app.activitythread.main(activitythread.java:4998)

04-19 23:30:54.308: e/androidruntime(1184): @ java.lang.reflect.method.invokenative(native method)

04-19 23:30:54.308: e/androidruntime(1184): @ java.lang.reflect.method.invoke(method.java:515)

04-19 23:30:54.308: e/androidruntime(1184): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:777)

04-19 23:30:54.308: e/androidruntime(1184): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:593)

04-19 23:30:54.308: e/androidruntime(1184): @ dalvik.system.nativestart.main(native method)

04-19 23:30:54.308: e/androidruntime(1184): caused by: java.lang.reflect.invocationtargetexception

04-19 23:30:54.308: e/androidruntime(1184): @ java.lang.reflect.method.invokenative(native method)

04-19 23:30:54.308: e/androidruntime(1184): @ java.lang.reflect.method.invoke(method.java:515)

04-19 23:30:54.308: e/androidruntime(1184): @ android.view.view$1.onclick(view.java:3809)

04-19 23:30:54.308: e/androidruntime(1184): ... 11 more

04-19 23:30:54.308: e/androidruntime(1184): caused by: java.lang.nullpointerexception

04-19 23:30:54.308: e/androidruntime(1184): @ com.colours.javerager.averageimageactivity.clicksavebutton(averageimageactivity.java:81)

04-19 23:30:54.308: e/androidruntime(1184): ... 14 more

please check 2 subject. such

number 1# check permission in androidmenifest.xml

 <uses-permission android:name="android.permission.write_external_storage" /> 

number 2# check javerager_swatches exist directory or not in sd card.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -