Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9129511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:45:55+00:00 2026-06-17T07:45:55+00:00

I have two methods to update and delete data in my app, I have

  • 0

I have two methods to update and delete data in my app, I have implemeted try catches within my switch statement and am now getting the following error:

01-14 20:38:58.778: D/AndroidRuntime(273): Shutting down VM
01-14 20:38:58.778: W/dalvikvm(273): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-14 20:38:58.798: E/AndroidRuntime(273): FATAL EXCEPTION: main
01-14 20:38:58.798: E/AndroidRuntime(273): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.flybase2/com.example.flybase2.viewEdit}: java.lang.NullPointerException
01-14 20:38:58.798: E/AndroidRuntime(273):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
01-14 20:38:58.798: E/AndroidRuntime(273):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-14 20:38:58.798: E/AndroidRuntime(273):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-14 20:38:58.798: E/AndroidRuntime(273):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-14 20:38:58.798: E/AndroidRuntime(273):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-14 20:38:58.798: E/AndroidRuntime(273):  at android.os.Looper.loop(Looper.java:123)
01-14 20:38:58.798: E/AndroidRuntime(273):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-14 20:38:58.798: E/AndroidRuntime(273):  at java.lang.reflect.Method.invokeNative(Native Method)
01-14 20:38:58.798: E/AndroidRuntime(273):  at java.lang.reflect.Method.invoke(Method.java:521)
01-14 20:38:58.798: E/AndroidRuntime(273):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-14 20:38:58.798: E/AndroidRuntime(273):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-14 20:38:58.798: E/AndroidRuntime(273):  at dalvik.system.NativeStart.main(Native Method)
01-14 20:38:58.798: E/AndroidRuntime(273): Caused by: java.lang.NullPointerException
01-14 20:38:58.798: E/AndroidRuntime(273):  at com.example.flybase2.viewEdit.<init>(viewEdit.java:63)
01-14 20:38:58.798: E/AndroidRuntime(273):  at java.lang.Class.newInstanceImpl(Native Method)
01-14 20:38:58.798: E/AndroidRuntime(273):  at java.lang.Class.newInstance(Class.java:1429)
01-14 20:38:58.798: E/AndroidRuntime(273):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-14 20:38:58.798: E/AndroidRuntime(273):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
01-14 20:38:58.798: E/AndroidRuntime(273):  ... 11 more

Can anyone see the issue? It works perfectly without the try catches.

Heres the class:

package com.example.flybase2;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class viewEdit extends Activity implements OnClickListener{

EditText namePassedEdit;
EditText numPassedEdit;
EditText emailPassedEdit;
EditText commentPassedEdit;
Button bUpdate;
Button bDelete;
long passedID = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.editview);

DBHandler displayEdit = new DBHandler(this, null, null);


        Bundle extras = getIntent().getExtras(); 
        if (extras != null) {
            passedID = extras.getLong("passedID"); 
        }
        displayEdit.open();
        String returnedNameToEdit = displayEdit.getName(passedID);
        String returnedNumToEdit  = displayEdit.getNum(passedID);
        String returnedEmailToEdit  = displayEdit.getEmail(passedID);
        String returnedCommentToEdit = displayEdit.getComments(passedID); 

    namePassedEdit = (EditText) findViewById(R.id.inputNameEdit);
    numPassedEdit = (EditText) findViewById(R.id.inputTelNoEdit);
    emailPassedEdit = (EditText) findViewById(R.id.inputEmailEdit);
    commentPassedEdit = (EditText) findViewById(R.id.inputCommentEdit);
    bUpdate = (Button) findViewById (R.id.btnAddConEdit);
    bDelete = (Button) findViewById (R.id.btnDeleteContact);



        namePassedEdit.setText(returnedNameToEdit);
        numPassedEdit.setText(returnedNumToEdit);
        emailPassedEdit.setText(returnedEmailToEdit);
        commentPassedEdit.setText(returnedCommentToEdit);


        bUpdate.setOnClickListener(this);
        bDelete.setOnClickListener(this);
}



String nameEdit = namePassedEdit.getText().toString();
String telEdit = numPassedEdit.getText().toString();
String emailEdit = emailPassedEdit.getText().toString();
String commentEdit = commentPassedEdit.getText().toString();

@Override
public void onClick(View updateOrDeleteClicked) {
    boolean check = true;
switch(updateOrDeleteClicked.getId()){

    case (R.id.btnAddConEdit):


        try
    {

        DBHandler updateData = new DBHandler(this, null, null);
        updateData.open();
        updateData.updateData(passedID, nameEdit, telEdit, emailEdit, commentEdit);
    } 
    catch (Exception e)
    {
        check = false;

        Dialog d = new Dialog(this);
        d.setTitle("Contact failed to be deleted.");
        TextView txt = new TextView(this);
        txt.setText("Fail");
        d.setContentView(txt);
        d.show();
    }
    finally
    {
        if(check = true);
        {

            Dialog e = new Dialog(this);
            e.setTitle("Contact deleted.");
            TextView txt = new TextView(this);
            txt.setText("Success");
            e.setContentView(txt);
            e.show();
        }
    }


        break;


    case (R.id.btnDeleteContact):





    try
{

        DBHandler deleteContact = new DBHandler(this, null, null);
        deleteContact.open();
        deleteContact.deleteData(passedID);
} 
catch (Exception e)
{
    check = false;

    Dialog d = new Dialog(this);
    d.setTitle("Contact failed to be deleted.");
    TextView txt = new TextView(this);
    txt.setText("Fail");
    d.setContentView(txt);
    d.show();
}
finally
{
    if(check = true);
    {

        Dialog e = new Dialog(this);
        e.setTitle("Contact deleted.");
        TextView txt = new TextView(this);
        txt.setText("Success");
        e.setContentView(txt);
        e.show();
    }
}


    break;
}

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:45:57+00:00Added an answer on June 17, 2026 at 7:45 am
    String nameEdit = namePassedEdit.getText().toString();
    String telEdit = numPassedEdit.getText().toString();
    String emailEdit = emailPassedEdit.getText().toString();
    String commentEdit = commentPassedEdit.getText().toString();
    

    These lines aren’t inside a method, and you can’t use them like that. You’re getting a null pointer on namePassedEdit because it’s trying to initialize them when the class is created, and they aren’t assigned anything yet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two domains: accounts.example.org app.example.org Now I want to do a HTTP DELETE
I have two methods declared public void MethodA(object o, Action<string> action) { } public
I have two methods -a and -b. -a calls sometimes -b, and -b sometimes
I have two methods, the first needs a Map<ItemA, ItemB> the second a Map<ItemA
I have two methods, one called straight after another, which both throw the exact
I have two methods, one that I use to convert an image to a
lets say I have two methods in my controller to support both json and
Is it possible to have two methods with the same name but different parameters
Let say I have two methods in MVC 4 Web API controller: public IQueryable<A>
Can somebody explain me one thing. I have two methods in my controller :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.