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 316605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:23:58+00:00 2026-05-12T08:23:58+00:00

I want to get the Text data value from Sub-Activity back. And everything is

  • 0

I want to get the Text data value from Sub-Activity back. And everything is ok. But when the Sub-activity was opened, then I just click back “button” on the phone, it throw an exception error. I found on the android NotePad life-cycle control toturial but It’s hard to understand. Can someone help me? This is my code:

public class SBooks extends ListActivity {
private String title_raw;
private SBooksDbAdapter mDbHelper;  
private static final int ACTIVITY_SEARCH = 0;   

private static final int SEARCH_ID = Menu.FIRST;     

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sbooks_list);       
    mDbHelper = new SBooksDbAdapter(this);
    mDbHelper.open();                    

}

// Create Menu Option
@Override
public boolean onCreateOptionsMenu(Menu menu) {        
    boolean result = super.onCreateOptionsMenu(menu);
    menu.add(0, SEARCH_ID, 0, R.string.menu_search);            
    return result;      
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()){
    case SEARCH_ID:
        Intent intent = new Intent(this, SBooksSearch.class);
        startActivityForResult(intent, ACTIVITY_SEARCH);            

    return super.onOptionsItemSelected(item);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
    super.onActivityResult(requestCode, resultCode, intent);
        switch(requestCode){
        case ACTIVITY_SEARCH:
            Bundle bundle = intent.getExtras();
            title_raw = bundle.getString(SBooksDbAdapter.KEY_TITLE_RAW);
            if(title_raw!=null){
                Cursor cursor = mDbHelper.searchData(title_raw);
                String[] from = new String[]{ SBooksDbAdapter.KEY_ROWID,
                        SBooksDbAdapter.KEY_TITLE, SBooksDbAdapter.KEY_LYRICS };
                int[] to = new int[]{ R.id.id, R.id.title, R.id.lyrics };
                SimpleCursorAdapter adapter = 
                    new SimpleCursorAdapter(this, R.layout.sbooks_row, cursor, from, to );
                setListAdapter(adapter);

        }

    }   
}

}

This is my Sub-Activity:

public class SBooksSearch extends Activity {
private EditText mTextSearch;
private Button searchButton;
private SBooksDbAdapter mDbHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);     
    setContentView(R.layout.sbooks_search); 

    mTextSearch = (EditText)findViewById(R.id.text_search);     
    searchButton = (Button)findViewById(R.id.btn_search);       

    searchButton.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v){                
            Intent intent = new Intent();
            intent.putExtra(SBooksDbAdapter.KEY_TITLE_RAW, mTextSearch.getText().toString());               
            setResult(RESULT_OK, intent);
            finish();

        }
    });
}   

@Override
protected void onSaveInstanceState(Bundle outState){
    super.onSaveInstanceState(outState);

}
@Override
protected void onPause(){
    super.onPause();
    checkState();

}
@Override
protected void onResume(){
    super.onResume();       
}


private void checkState() {     

} }

This is Logcat:

08-12 18:44:39.211: WARN/InputManagerService(581): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@43719140 (uid=10004 pid=623)
08-12 18:44:39.510: INFO/ActivityManager(581): Displayed activity com.original.sbooks/.SBooks: 4934 ms
08-12 18:44:40.821: WARN/KeyCharacterMap(730): No keyboard for id 0
08-12 18:44:40.821: WARN/KeyCharacterMap(730): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
08-12 18:44:41.412: INFO/ARMAssembler(581): generated scanline__00000177:03515104_00001A01_00000000 [ 64 ipp] (89 ins) at [0x297608:0x29776c] in 952924 ns
08-12 18:44:41.520: INFO/ARMAssembler(581): generated scanline__00000177:03515104_00000A01_00000000 [ 46 ipp] (70 ins) at [0x297798:0x2978b0] in 517061 ns
08-12 18:44:42.171: INFO/ActivityManager(581): Starting activity: Intent { comp={com.original.sbooks/com.original.sbooks.SBooksSearch} }
08-12 18:44:52.196: WARN/ActivityManager(581): Launch timeout has expired, giving up wake lock!
08-12 18:44:52.279: WARN/ActivityManager(581): Activity idle timeout for HistoryRecord{436bfc80 {com.original.sbooks/com.original.sbooks.SBooksSearch}}
08-12 18:44:57.350: DEBUG/dalvikvm(620): GC freed 4103 objects / 231808 bytes in 75ms
08-12 18:45:05.130: DEBUG/dalvikvm(649): GC freed 2604 objects / 150112 bytes in 88ms
08-12 18:45:10.120: DEBUG/dalvikvm(623): GC freed 2750 objects / 149592 bytes in 71ms
08-12 18:45:11.920: INFO/ActivityManager(581): Displayed activity com.original.sbooks/.SBooksSearch: 29748 ms
08-12 18:45:17.263: WARN/ActivityManager(581): Activity pause timeout for HistoryRecord{436bfc80 {com.original.sbooks/com.original.sbooks.SBooksSearch}}
08-12 18:45:26.762: WARN/ActivityManager(581): Launch timeout has expired, giving up wake lock!
08-12 18:45:27.272: WARN/ActivityManager(581): Activity idle timeout for HistoryRecord{435a7760 {com.original.sbooks/com.original.sbooks.SBooks}}
08-12 18:46:04.905: DEBUG/AndroidRuntime(730): Shutting down VM
08-12 18:46:04.905: WARN/dalvikvm(730): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
08-12 18:46:04.905: ERROR/AndroidRuntime(730): Uncaught handler: thread main exiting due to uncaught exception
08-12 18:46:04.991: ERROR/AndroidRuntime(730): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=0, data=null} to activity {com.original.sbooks/com.original.sbooks.SBooks}: java.lang.NullPointerException
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3005)
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3047)
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at android.app.ActivityThread.access$2300(ActivityThread.java:112)
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1721)
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at android.os.Looper.loop(Looper.java:123)
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at android.app.ActivityThread.main(ActivityThread.java:3948)
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at java.lang.reflect.Method.invokeNative(Native Method)
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at java.lang.reflect.Method.invoke(Method.java:521)
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at dalvik.system.NativeStart.main(Native Method)
08-12 18:46:04.991: ERROR/AndroidRuntime(730): Caused by: java.lang.NullPointerException
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at com.original.sbooks.SBooks.onActivityResult(SBooks.java:111)
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at android.app.Activity.dispatchActivityResult(Activity.java:3595)
08-12 18:46:04.991: ERROR/AndroidRuntime(730):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3001)
  • 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-12T08:23:58+00:00Added an answer on May 12, 2026 at 8:23 am

    I think Nate is correct about the NPE at intent.getExtras().

    You should be checking the value of your result code before you do anything. You also might want to check to make sure intent.hasExtra(SBooksDbAdapter.KEY_TITLE_RAW) before you get that value. So, something like this:

    switch(requestCode){
    case ACTIVITY_SEARCH:
        if (resultCode == RESULT_OK && intent.hasExtra(SBooksDbAdapter.KEY_TITLE_RAW)) {
            title_raw = intent.getStringExtra(SBooksDbAdapter.KEY_TITLE_RAW);
            ... do all that other stuff ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

got a few question here. i just want to get the data from the
I want to get text from current active line (the line where the caret
I want to get back the text that I select in an element using
I want to write the text (which I get from AJAX) to a file,
I want to read an existing PDF file, get not only the text, but
I want to get the data from this page and insert it to my
I get a good string value from the following Data-Binding expression in a ASP.NET
Im trying to send via ajax a value from a textfield, but don't want
I want to get the Text property from a TextBox that is inside a
I have a problem, when I want get some data from CSV file to

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.