I am trying to make it so that when a button is pressed an alertdialogue pops up with a spinner in it, and in the spinner there are three options, how can i make it so that when one of the options are selected the alertdialogue disappears, my code below crashed whenever I select something from the spinner
Below is my code
public void AlertD() {
LayoutInflater li = LayoutInflater.from(getActivity());
View promptsView = li.inflate(R.layout.abs, null);
// above I am setting the customview of the alert dialogue
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
getActivity());
alertDialogBuilder.setView(promptsView);
// here I am officially setting the custom layout
// set dialog message
alertDialogBuilder.setTitle(dialoguechoice + " Stretch Type");
// alert dialogue title
// create alert dialog
final AlertDialog alertDialog = alertDialogBuilder.create();
// above is creating the alert dialogue
final Spinner mSpinner = (Spinner) promptsView
.findViewById(R.id.sSType);
// above is initializing the spinner
// reference UI elements from my_dialog_layout in similar fashion
mSpinner.setOnItemSelectedListener(new OnSpinnerItemClicked());
// show it
alertDialog.show();
alertDialog.setCanceledOnTouchOutside(true);
}
Below is my listener
public class OnSpinnerItemClicked implements OnItemSelectedListener {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
switch (pos) {
case (1):
alertDialog.dismiss();
break;
}
}
#Override
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
}
EDIT logcat is below
06-18 18:09:55.939: E/AndroidRuntime(4355): FATAL EXCEPTION: main
06-18 18:09:55.939: E/AndroidRuntime(4355): java.lang.NullPointerException
06-18 18:09:55.939: E/AndroidRuntime(4355): at com.OptimusApps.stayhealthy.Body$OnSpinnerItemClicked.onItemSelected(Body.java:178)
06-18 18:09:55.939: E/AndroidRuntime(4355): at android.widget.AdapterView.fireOnSelected(AdapterView.java:882)
06-18 18:09:55.939: E/AndroidRuntime(4355): at android.widget.AdapterView.access$200(AdapterView.java:48)
06-18 18:09:55.939: E/AndroidRuntime(4355): at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:848)
06-18 18:09:55.939: E/AndroidRuntime(4355): at android.os.Handler.handleCallback(Handler.java:605)
06-18 18:09:55.939: E/AndroidRuntime(4355): at android.os.Handler.dispatchMessage(Handler.java:92)
06-18 18:09:55.939: E/AndroidRuntime(4355): at android.os.Looper.loop(Looper.java:137)
06-18 18:09:55.939: E/AndroidRuntime(4355): at android.app.ActivityThread.main(ActivityThread.java:4575)
06-18 18:09:55.939: E/AndroidRuntime(4355): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 18:09:55.939: E/AndroidRuntime(4355): at java.lang.reflect.Method.invoke(Method.java:511)
06-18 18:09:55.939: E/AndroidRuntime(4355): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-18 18:09:55.939: E/AndroidRuntime(4355): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
06-18 18:09:55.939: E/AndroidRuntime(4355): at dalvik.system.NativeStart.main(Native Method)
Thanks
Related
Im trying to get imageview size but its returning zero. i know its because im calling it in onCreate(). can anyone help me how to do this so that when I will click a button it will show me the size of that ImageView. here what i have tried so far...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button)findViewById(R.id.btn);
imgView = (ImageView)findViewById(R.id.imgView);
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
getSize();
}
});
}
void getSize)
{
BitmapDrawable bd = (BitmapDrawable)imgView.getDrawable();
bmp = bd.getBitmap();
Bitmap op = Bitmap.createBitmap(bmp, imgWidth/2, imgHeight/2, imgWidth, imgHeight);
imgView.setImageBitmap(op);
}
#Override
public void onWindowFocusChanged(boolean hasFocus){
imgWidth=imgView.getWidth();
imgHeight=imgView.getHeight();
}
UPDATE
This is what I am getting right now...
06-18 00:13:20.206: E/AndroidRuntime(919): FATAL EXCEPTION: main
06-18 00:13:20.206: E/AndroidRuntime(919): java.lang.IllegalArgumentException: x must be >= 0
06-18 00:13:20.206: E/AndroidRuntime(919): at android.graphics.Bitmap.checkXYSign(Bitmap.java:225)
06-18 00:13:20.206: E/AndroidRuntime(919): at android.graphics.Bitmap.createBitmap(Bitmap.java:495)
06-18 00:13:20.206: E/AndroidRuntime(919): at android.graphics.Bitmap.createBitmap(Bitmap.java:471)
06-18 00:13:20.206: E/AndroidRuntime(919): at com.example.bitmapfun.Main.Gray(Main.java:44)
06-18 00:13:20.206: E/AndroidRuntime(919): at com.example.bitmapfun.Main$1.onClick(Main.java:34)
06-18 00:13:20.206: E/AndroidRuntime(919): at android.view.View.performClick(View.java:3527)
06-18 00:13:20.206: E/AndroidRuntime(919): at android.view.View$PerformClick.run(View.java:14234)
06-18 00:13:20.206: E/AndroidRuntime(919): at android.os.Handler.handleCallback(Handler.java:605)
06-18 00:13:20.206: E/AndroidRuntime(919): at android.os.Handler.dispatchMessage(Handler.java:92)
06-18 00:13:20.206: E/AndroidRuntime(919): at android.os.Looper.loop(Looper.java:137)
06-18 00:13:20.206: E/AndroidRuntime(919): at android.app.ActivityThread.main(ActivityThread.java:4441)
06-18 00:13:20.206: E/AndroidRuntime(919): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 00:13:20.206: E/AndroidRuntime(919): at java.lang.reflect.Method.invoke(Method.java:511)
06-18 00:13:20.206: E/AndroidRuntime(919): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-18 00:13:20.206: E/AndroidRuntime(919): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-18 00:13:20.206: E/AndroidRuntime(919): at dalvik.system.NativeStart.main(Native Method)
Try this it uses view tree observer for getting the width and height. The earlier methods didnot work because the view was not drawn in the screen(layout pass incomplete). Something similar should work:
final ImageView iv = (ImageView)findViewById(R.id.image);
ViewTreeObserver vto = iv.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
Log.d("width",""+iv.getWidth());
}
});
The size isn't set up until the component is added to the parent window, and then the window is "packed" or laid out to the right size. So in the onCreate, it will be 0,0
Can't you just get the size when the function is called?
void getSize()
{
imgWidth=imgView.getWidth();
imgHeight=imgView.getHeight();
BitmapDrawable bd = (BitmapDrawable)imgView.getDrawable();
bmp = bd.getBitmap();
Bitmap op = Bitmap.createBitmap(bmp, imgWidth/2, imgHeight/2, imgWidth, imgHeight);
imgView.setImageBitmap(op);
}
this is the code...plz let me know where did i go wrong.. also i am setting an adapter to the listview which is conatined in the View v1 inflated...this is all done in the extension response of a smartfox server...and then the following process on UI Thread..
runOnUiThread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
alert();
}
});
public void alert(){
AlertDialog.Builder ab=new AlertDialog.Builder(RegActivity.this);
LayoutInflater linf=(LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View v1=linf.inflate(R.layout.proj_list, null);
ab.setView(v1);
ab.setTitle("Select a group");
ListView lvprojlist=(ListView) findViewById(R.id.projdisplaylist);
adplist=new ArrayAdapter<String>(RegActivity.this, R.layout.list_item, R.id.rowtext, projlist);
lvprojlist.setAdapter(adplist);
ab.setCancelable(false).setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
ab.create();
ab.show();
}
this is my logcat output..
12-19 17:14:33.869: W/dalvikvm(699): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-19 17:14:33.889: E/AndroidRuntime(699): FATAL EXCEPTION: main
12-19 17:14:33.889: E/AndroidRuntime(699): java.lang.NullPointerException
12-19 17:14:33.889: E/AndroidRuntime(699): at com.registersfsmodule.RegActivity.alert(RegActivity.java:392)
12-19 17:14:33.889: E/AndroidRuntime(699): at com.registersfsmodule.RegActivity$3$2.run(RegActivity.java:178)
12-19 17:14:33.889: E/AndroidRuntime(699): at android.os.Handler.handleCallback(Handler.java:587)
12-19 17:14:33.889: E/AndroidRuntime(699): at android.os.Handler.dispatchMessage(Handler.java:92)
12-19 17:14:33.889: E/AndroidRuntime(699): at android.os.Looper.loop(Looper.java:130)
12-19 17:14:33.889: E/AndroidRuntime(699): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-19 17:14:33.889: E/AndroidRuntime(699): at java.lang.reflect.Method.invokeNative(Native Method)
12-19 17:14:33.889: E/AndroidRuntime(699): at java.lang.reflect.Method.invoke(Method.java:507)
12-19 17:14:33.889: E/AndroidRuntime(699): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-19 17:14:33.889: E/AndroidRuntime(699): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-19 17:14:33.889: E/AndroidRuntime(699): at dalvik.system.NativeStart.main(Native Method)
You have to first change this in reverse order.
ab.setTitle("Select a group");
ListView lvprojlist=(ListView) v1.findViewById(R.id.projdisplaylist);
ab.setView(v1);
You have to set view after find id of your ListView.
Also don't make adplist variable globally. Make it static.
ArrayAdapter<String >adplist=new ArrayAdapter<String>(RegActivity.this, R.layout.list_item, R.id.rowtext, projlist);
I've just started to look at Android development and I followed a tutorial on how to make a super simple basic calculator (with just sum, sub, div and mult operations) but my APP is full of bugs and one of them is crashing when I do an operation without any inserted values.
This is just a portion of the code and I think the crash is in this part (for every button). How can I solve this issue without crashing the app? Like doing nothing when one TextEdit is blank? Do I need any throw/catch exception?
sub.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
firstNum = new BigDecimal(firstNumber.getText().toString());
secondNum = new BigDecimal(secNumber.getText().toString());
if (firstNum == null || secondNum == null) {
while (verificar) {
}
} else {
result.setText(firstNum.subtract(secondNum).toString());
}
}
});
The logcat.txt of the errors...
Thanks for your patience...
06-18 16:39:51.018: E/AndroidRuntime(621): FATAL EXCEPTION: main
06-18 16:39:51.018: E/AndroidRuntime(621): java.lang.NumberFormatException: Bad offset/length: offset=0 len=0 in.length=0
06-18 16:39:51.018: E/AndroidRuntime(621): at java.math.BigDecimal.<init>(BigDecimal.java:282)
06-18 16:39:51.018: E/AndroidRuntime(621): at java.math.BigDecimal.<init>(BigDecimal.java:438)
06-18 16:39:51.018: E/AndroidRuntime(621): at com.example.simplecalculator.Calculadora$1.onClick(Calculadora.java:44)
06-18 16:39:51.018: E/AndroidRuntime(621): at android.view.View.performClick(View.java:4084)
06-18 16:39:51.018: E/AndroidRuntime(621): at android.view.View$PerformClick.run(View.java:16966)
06-18 16:39:51.018: E/AndroidRuntime(621): at android.os.Handler.handleCallback(Handler.java:615)
06-18 16:39:51.018: E/AndroidRuntime(621): at android.os.Handler.dispatchMessage(Handler.java:92)
06-18 16:39:51.018: E/AndroidRuntime(621): at android.os.Looper.loop(Looper.java:137)
06-18 16:39:51.018: E/AndroidRuntime(621): at android.app.ActivityThread.main(ActivityThread.java:4745)
06-18 16:39:51.018: E/AndroidRuntime(621): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 16:39:51.018: E/AndroidRuntime(621): at java.lang.reflect.Method.invoke(Method.java:511)
06-18 16:39:51.018: E/AndroidRuntime(621): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
06-18 16:39:51.018: E/AndroidRuntime(621): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-18 16:39:51.018: E/AndroidRuntime(621): at dalvik.system.NativeStart.main(Native Method)
06-18 16:41:07.109: E/Trace(644): error opening trace file: No such file or directory (2)
06-18 16:41:09.339: E/AndroidRuntime(644): FATAL EXCEPTION: main
06-18 16:41:09.339: E/AndroidRuntime(644): java.lang.NumberFormatException: Bad offset/length: offset=0 len=0 in.length=0
06-18 16:41:09.339: E/AndroidRuntime(644): at java.math.BigDecimal.<init>(BigDecimal.java:282)
06-18 16:41:09.339: E/AndroidRuntime(644): at java.math.BigDecimal.<init>(BigDecimal.java:438)
06-18 16:41:09.339: E/AndroidRuntime(644): at com.example.simplecalculator.Calculadora$1.onClick(Calculadora.java:44)
06-18 16:41:09.339: E/AndroidRuntime(644): at android.view.View.performClick(View.java:4084)
06-18 16:41:09.339: E/AndroidRuntime(644): at android.view.View$PerformClick.run(View.java:16966)
06-18 16:41:09.339: E/AndroidRuntime(644): at android.os.Handler.handleCallback(Handler.java:615)
06-18 16:41:09.339: E/AndroidRuntime(644): at android.os.Handler.dispatchMessage(Handler.java:92)
06-18 16:41:09.339: E/AndroidRuntime(644): at android.os.Looper.loop(Looper.java:137)
06-18 16:41:09.339: E/AndroidRuntime(644): at android.app.ActivityThread.main(ActivityThread.java:4745)
06-18 16:41:09.339: E/AndroidRuntime(644): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 16:41:09.339: E/AndroidRuntime(644): at java.lang.reflect.Method.invoke(Method.java:511)
06-18 16:41:09.339: E/AndroidRuntime(644): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
06-18 16:41:09.339: E/AndroidRuntime(644): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-18 16:41:09.339: E/AndroidRuntime(644): at dalvik.system.NativeStart.main(Native Method)
The assignment of the BigDecimal will throw a NumberFormatException if the string is empty. Change this:
firstNum = new BigDecimal(firstNumber.getText().toString());
secondNum = new BigDecimal(secNumber.getText().toString());
to this:
try {
firstNum = new BigDecimal(firstNumber.getText().toString());
} catch (NumberFormatException e) {
firstNum = null;
}
try {
secondNum = new BigDecimal(secNumber.getText().toString());
} catch (NumberFormatException e) {
secondNum = null;
}
I see this error popping almost a million times and people have got the help. As a beginner, I would like to seek some help for the simple media recorder that I'm developing. Please help.
Below mentioned is the code-
add_company.java
public class add_company extends Activity{
//Adding for voice record
ImageButton play,record,stop;
private String s,voicerec;
MediaPlayer mp;
MediaRecorder mr;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.add_company);
//Adding voice record
play = (ImageButton)findViewById(R.id.Play);
record = (ImageButton)findViewById(R.id.Record);
stop = (ImageButton)findViewById(R.id.Stop);
File audioFile = null;
try {
audioFile = File.createTempFile(null, ".amr");
} catch (IOException e1) {
e1.printStackTrace();
}
mr = new MediaRecorder();
s = audioFile.getAbsolutePath();
voicerec=s;
System.out.println("Path: "+s);
mr.setAudioSource(MediaRecorder.AudioSource.MIC);
mr.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mr.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mr.setOutputFile(s);
try{
mr.prepare();
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
public void record(View v){
Toast.makeText(add_company.this, "Recording", Toast.LENGTH_LONG).show();
mr.start();
}
public void stop(View v){
mr.stop(); //this is stop recording
Toast.makeText(add_company.this, "Stopped", Toast.LENGTH_LONG).show();
mr.reset(); // this is required to avoid the error: Fatal signal 11 (SIGSEGV) at 0x00000010 (code=1)
mr.release();
}
public void play(View v){
File f = new File(voicerec);
Uri u = Uri.fromFile(f);
mp = MediaPlayer.create(add_company.this, u);
mp.setLooping(false);
mp.start();
}
}
LogCat details:
06-18 10:31:53.281: E/AndroidRuntime(2740): FATAL EXCEPTION: main
06-18 10:31:53.281: E/AndroidRuntime(2740): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tg_db1/com.example.tg_db1.add_company}: java.lang.NullPointerException
06-18 10:31:53.281: E/AndroidRuntime(2740): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-18 10:31:53.281: E/AndroidRuntime(2740): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-18 10:31:53.281: E/AndroidRuntime(2740): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-18 10:31:53.281: E/AndroidRuntime(2740): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-18 10:31:53.281: E/AndroidRuntime(2740): at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 10:31:53.281: E/AndroidRuntime(2740): at android.os.Looper.loop(Looper.java:137)
06-18 10:31:53.281: E/AndroidRuntime(2740): at android.app.ActivityThread.main(ActivityThread.java:5039)
06-18 10:31:53.281: E/AndroidRuntime(2740): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 10:31:53.281: E/AndroidRuntime(2740): at java.lang.reflect.Method.invoke(Method.java:511)
06-18 10:31:53.281: E/AndroidRuntime(2740): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-18 10:31:53.281: E/AndroidRuntime(2740): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-18 10:31:53.281: E/AndroidRuntime(2740): at dalvik.system.NativeStart.main(Native Method)
06-18 10:31:53.281: E/AndroidRuntime(2740): Caused by: java.lang.NullPointerException
06-18 10:31:53.281: E/AndroidRuntime(2740): at java.io.File.createTempFile(File.java:999)
06-18 10:31:53.281: E/AndroidRuntime(2740): at java.io.File.createTempFile(File.java:970)
06-18 10:31:53.281: E/AndroidRuntime(2740): at com.example.tg_db1.add_company.onCreate(add_company.java:64)
06-18 10:31:53.281: E/AndroidRuntime(2740): at android.app.Activity.performCreate(Activity.java:5104)
06-18 10:31:53.281: E/AndroidRuntime(2740): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-18 10:31:53.281: E/AndroidRuntime(2740): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-18 10:31:53.281: E/AndroidRuntime(2740): ... 11 more
File.createTempFile(null, ".amr");
Prefix can't be null.
From the source code :
public static File createTempFile(String prefix, String suffix, File directory) throws IOException
{
if (prefix == null) throw new NullPointerException();
/***/
}
This code I am working on requires the user to press a button after entering a phone number into a text box. The button is made to save the number.
When I run the code I want to have it present the user with an alert dialog asking them to enter a number if they pressed the button with no number present.
Instead of getting the alert dialog the app crashes. But with a number entered the app works just fine.
Any advice on this would be awesome - Here is the code with the stack trace under that.
-Thank you!
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Create an if statement that brings up an alert dialog if there is no number entered into the field.
switch (v.getId()) {
case R.id.btnwidgetconfig: {
if (sharedData == null)
{
AlertDialog.Builder alert = new AlertDialog.Builder(c);
alert.setTitle("No number entered");
alert.setMessage("Please enter a phone number using the the text box");
alert.setCancelable(false);
alert.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivityForResult(
new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS),
0);
}
});
}
else
{
String stringData = sharedData.getText().toString();
Long l = Long.parseLong(stringData);
SharedPreferences.Editor editor = prefs.edit();
prefs.edit().putLong(constants.KEY, l).commit();
Toast.makeText(c, "Your number has been saved!",
Toast.LENGTH_LONG).show();
svNum.setText("Saved Number: " + prefs.getLong(constants.KEY, 411));
break;
}
}
}
}
});
////Stack Trace:
05-14 12:29:07.679: W/dalvikvm(30842): threadid=1: thread exiting with uncaught exception (group=0x40018560)
05-14 12:29:07.679: E/AndroidRuntime(30842): FATAL EXCEPTION: main
05-14 12:29:07.679: E/AndroidRuntime(30842): java.lang.NumberFormatException:
05-14 12:29:07.679: E/AndroidRuntime(30842): at java.lang.Long.parseLong(Long.java:337)
05-14 12:29:07.679: E/AndroidRuntime(30842): at java.lang.Long.parseLong(Long.java:311)
05-14 12:29:07.679: E/AndroidRuntime(30842): at example.save.phonenum.Settings$1.onClick(WWSettings.java:106)
05-14 12:29:07.679: E/AndroidRuntime(30842): at android.view.View.performClick(View.java:2485)
05-14 12:29:07.679: E/AndroidRuntime(30842): at android.view.View$PerformClick.run(View.java:9080)
05-14 12:29:07.679: E/AndroidRuntime(30842): at android.os.Handler.handleCallback(Handler.java:587)
05-14 12:29:07.679: E/AndroidRuntime(30842): at android.os.Handler.dispatchMessage(Handler.java:92)
05-14 12:29:07.679: E/AndroidRuntime(30842): at android.os.Looper.loop(Looper.java:130)
05-14 12:29:07.679: E/AndroidRuntime(30842): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-14 12:29:07.679: E/AndroidRuntime(30842): at java.lang.reflect.Method.invokeNative(Native Method)
05-14 12:29:07.679: E/AndroidRuntime(30842): at java.lang.reflect.Method.invoke(Method.java:507)
05-14 12:29:07.679: E/AndroidRuntime(30842): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
05-14 12:29:07.679: E/AndroidRuntime(30842): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
05-14 12:29:07.679: E/AndroidRuntime(30842): at dalvik.system.NativeStart.main(Native Method)
05-14 12:29:15.569: W/IInputConnectionWrapper(30870): showStatusIcon on inactive InputConnection
I'm guessing this sharedData is a TextView. Which you are still trying to parse the result when it is null, hence the NFE. Put in a check to only run that code if there is a valid number. You are checking if it is null, which the TextView may not be but the contents are an empty String which you are trying to parse
Change
if (sharedData == null)
to something like
if (sharedData == null || sharedData.getText().toString().equals(""))
{
...
I would try to get the text before that line into your stringData variable then check if that is empty. Also, you will want to put a try/catch around the parsing code in case they try to enter a non-digit and display a message, unless you've already done that