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

  • SEARCH
  • Home
  • 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 6339193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:36:06+00:00 2026-05-24T19:36:06+00:00

I have an Activity SaveData.class with a public method addEvent() use to add some

  • 0

I have an Activity SaveData.class with a public method addEvent() use to add some information in a DataBase table as follows:

public class SaveData extends Activity implements OnClickListener {

public SoftCopyDatabase dB ;
public static String FILE_NAME;
String _subject, _topic,_lecturenumber,_date;


protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.save);
    View add = findViewById(R.id.saveSave);
    add.setOnClickListener(this);
    View home = findViewById(R.id.saveBack);
    home.setOnClickListener(this);

}public void onStart() {
    super.onStart();
    dB = new SoftCopyDatabase(this);
}

public void onStop() {
    super.onStop();
    if (dB.getReadableDatabase().isOpen()) {
        //dB.close();
    }
}
public void onDestroy() {
    super.onDestroy();
    if (dB.getReadableDatabase().isOpen()) {
        dB.close();
    }
}

public void onClick(View v) {
    switch (v.getId()) {
    case R.id.saveBack:
        Intent i = new Intent(this, OpenScreen.class);
        startActivity(i);
        break;
    case R.id.saveSave:

        EditText subject = (EditText) findViewById(R.id.subjectid);
        EditText topic = (EditText) findViewById(R.id.topicid);
        EditText lecturenumber = (EditText) findViewById(R.id.lecturenumberid);
        EditText date = (EditText) findViewById(R.id.dateid);
         _subject = ((TextView) subject).getText().toString();
         _topic = ((TextView) topic).getText().toString();
         _lecturenumber = ((TextView) lecturenumber).getText()
                .toString();
         _date = ((TextView) date).getText().toString();
        FILE_NAME = _subject + _topic + _lecturenumber;
        //addEvent();

        Intent j = new Intent(this, LectureNoting.class);
        startActivity(j);

        break;

    }
}

public void addEvent() {


    ContentValues values = new ContentValues();
    values.put(SUBJECT, _subject);
    values.put(TOPIC, _topic);
    values.put(LECTURENUMBER, _lecturenumber);
    values.put(DATE, _date);
    values.put(_DATA, FILE_NAME + ".png");
    dB.getWritableDatabase().insertOrThrow(TABLE_NAME, null, values);
}

}

Another activity LectureNoting.class is used to save Drawings on the disk and updates the entry in Database Table as follows:

public class LectureNoting extends Activity implements View.OnTouchListener{

private SaveData sD=new SaveData();
private File directory = new File("/sdcard/SoftCopy"); 
//...remaining code
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.drawing_activity);
    }
//...remaining code
public void onClick(View view){
    switch (view.getId()){
case R.id.saveBtn:
addEvent();
            final Activity currentActivity  = this;
    Handler saveHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {

            Toast.makeText(currentActivity, "Lecture Saved",   Toast.LENGTH_SHORT).show();

        }
    } ;
   new ExportBitmapToFile(this,saveHandler, softCopyInterface.getBitmap()).execute();
        break;
//...remaining code
}
private class ExportBitmapToFile extends AsyncTask<Intent,Void,Boolean> {
    private Context mContext;
    private Handler mHandler;
    private Bitmap nBitmap;

    public ExportBitmapToFile(Context context,Handler handler,Bitmap bitmap) {
        mContext = context;
        nBitmap = bitmap;
        mHandler = handler;
    }

    @Override
    protected Boolean doInBackground(Intent... arg0) {

        try {
            if (!directory.exists()) {
                directory.mkdirs();
            }

            final FileOutputStream out = new FileOutputStream(new File(directory + "/"+SaveData.FILE_NAME+".png"));

            nBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
            out.flush();
            out.close();

            return true;
        }

        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return false;
    }


    @Override
    protected void onPostExecute(Boolean bool) {
        super.onPostExecute(bool);
        if ( bool ){
            mHandler.sendEmptyMessage(1);
        }
    }
 }
}

And I am receiving following error:

       Unable to start activity componentInfo(com.ned.LectureNoting):NullPointerException

At the addEvent(), used in the onClick method of LectureNoting.

Kindly tell me where I am going wrong. One point I would like to mention is if addEvent() is called from the same activity in which it was defined, this error does not appear.

  • 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-05-24T19:36:08+00:00Added an answer on May 24, 2026 at 7:36 pm

    Couple of things:

    1. Logcat should be giving more information about the error. You may have to scroll down a bit to see the source of the problem in your code, but there should be more info.
    2. you shouldnt be defining public methods inside of classes that extend Activity to be used by other classes. If you want to expose some database method to multiple activities, then create a separate class for that and then call that method inside of your activity. You said LectureNoting extends Activity. You sure about this? You must have it extending SaveData if you are just calling addEvent() like that.

    Either way, DON’T CALL METHODS FROM ONE ACTIVITY INSIDE OF ANOTHER. If you want to expose a method to multiple activities, create it in it’s own class with a sensible name related to the group of functions that you expose.

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

Sidebar

Related Questions

I have a Activity class and a Renderer class (extends GLSurfaceView implements Renderer). Inside
I have ListView activity class: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] naziviMolitvi =
I have an activity that extends ExpandableListActivity. I use SimpleCursorTreeAdapter to fill ExpandableListView. My
I have Activity with ListView inside it and in the onCreate method of the
I have an activity which shows some List entries. When I click on a
I have an activity that launches another activity with startActivityForResult method. I would like
Going round in circles here i think. I have an activity called Locate; public
I Have activity that get some data from the internet, and shows it to
I am a begginer in android,here I have activity that use web service: SoapObject
I have Activity with some data displayed in WebView that I load with WebView#loadDataWithBaseURL

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.