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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:47:27+00:00 2026-06-01T09:47:27+00:00

I’m passing two strings between two activities and for some reason, it crashes when

  • 0

I’m passing two strings between two activities and for some reason, it crashes when I try to accept the string. I feel like, I’ve missed something important out, but can’t find any code, that I could of missed out. Google yielded, little to no results and I’m really annoyed as this seems to be a pretty basic task.

Any help, would be gratefully appreciated 🙂

LogCat:

 03-25 04:23:03.476: E/AndroidRuntime(1174): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gta5news.bananaphone/com.gta5news.bananaphone.ChatService}: java.lang.NullPointerException
03-25 04:23:03.476: E/AndroidRuntime(1174):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-25 04:23:03.476: E/AndroidRuntime(1174):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-25 04:23:03.476: E/AndroidRuntime(1174):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-25 04:23:03.476: E/AndroidRuntime(1174):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-25 04:23:03.476: E/AndroidRuntime(1174):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-25 04:23:03.476: E/AndroidRuntime(1174):     at android.os.Looper.loop(Looper.java:123)
03-25 04:23:03.476: E/AndroidRuntime(1174):     at android.app.ActivityThread.main(ActivityThread.java:4627)
03-25 04:23:03.476: E/AndroidRuntime(1174):     at java.lang.reflect.Method.invokeNative(Native Method)
03-25 04:23:03.476: E/AndroidRuntime(1174):     at java.lang.reflect.Method.invoke(Method.java:521)
03-25 04:23:03.476: E/AndroidRuntime(1174):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-25 04:23:03.476: E/AndroidRuntime(1174):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-25 04:23:03.476: E/AndroidRuntime(1174):     at dalvik.system.NativeStart.main(Native Method)
03-25 04:23:03.476: E/AndroidRuntime(1174): Caused by: java.lang.NullPointerException
03-25 04:23:03.476: E/AndroidRuntime(1174):     at com.gta5news.bananaphone.ChatService.GetLogInData(ChatService.java:76)
03-25 04:23:03.476: E/AndroidRuntime(1174):     at com.gta5news.bananaphone.ChatService.onCreate(ChatService.java:47)
03-25 04:23:03.476: E/AndroidRuntime(1174):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-25 04:23:03.476: E/AndroidRuntime(1174):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-25 04:23:03.476: E/AndroidRuntime(1174):     ... 11 more

Code(Second activity, that crashes)

  public class ChatService extends ListActivity {
    /** Called when the activity is first created. */

    BufferedReader in = null;
    String data = null;
    List headlines;
    List links;
    String GotPass = null;
    String GotUname = null;




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


        try {
            ContactsandIm();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            CheckLogin();
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }




    private void GetLogInData() {
        // TODO Auto-generated method stub
        Bundle gotData = getIntent().getExtras();
        GotPass = gotData.getString("key!");
        GotUname = gotData.getString("key!!");

    }




    private void CheckLogin() throws UnsupportedEncodingException {

    }
    public void ContactsandIm() throws URISyntaxException,
            ClientProtocolException, IOException {
        headlines = new ArrayList();

        // TODO Auto-generated method stub
        BufferedReader in = null;
        String data = null;

        HttpClient get = new DefaultHttpClient();
        URI website = new URI("http://www.gta5news.com/test.php");
        HttpGet webget = new HttpGet();
        webget.setURI(website);
        HttpResponse response = get.execute(webget);
        Log.w("HttpPost", "Execute HTTP Post Request");
        in = new BufferedReader(new InputStreamReader(response.getEntity()
                .getContent()));
        StringBuffer sb = new StringBuffer("");
        String l ="";
        String nl ="";
        while ((l =in.readLine()) !=null) {
            sb.append(l + nl);  
        }
        in.close();
         data = sb.toString();
         if(data.contains("null"));
         ListView lv = getListView();
         lv.setTextFilterEnabled(true);

        headlines.add(data);


        ArrayAdapter adapter = new ArrayAdapter(this,
                android.R.layout.simple_list_item_1, headlines);

        setListAdapter(adapter);



    }

    // end bracket for "ContactsandIm"

}

1st Activity

public class LogIn extends Activity implements OnClickListener {

    Button ok, back, exit;
    TextView result;
    EditText pword;
    EditText uname;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Login button clicked
        ok = (Button) findViewById(R.id.btn_login);
        ok.setOnClickListener(this);

        result = (TextView) findViewById(R.id.lbl_result);

    } 
    //create bracket.

    public void postLoginData() {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();

        /* login.php returns true if username and password is equal to saranga */
        HttpPost httppost = new HttpPost("http://gta5news.com/login.php");

        try {
            // Add user name and password
            uname = (EditText) findViewById(R.id.txt_username);
            String username = uname.getText().toString();


            pword = (EditText) findViewById(R.id.txt_password);
            String password = pword.getText().toString();
            Bundle basket = new Bundle();
            basket.putString("key!", password);
            basket.putString("key!!", username);
            Intent a = new Intent(LogIn.this, ChatService.class );
            a.putExtras(basket);
            startActivity(a);


            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("username", username));
            nameValuePairs.add(new BasicNameValuePair("password", password));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            Log.w("HttpPost", "Execute HTTP Post Request");
            HttpResponse response = httpclient.execute(httppost);

            String str = inputStreamToString(response.getEntity().getContent())
                    .toString();
            Log.w("HttpPost", str);

            if (str.toString().equalsIgnoreCase("true")) {
                Log.w("HttpPost", "TRUE");
                result.setText("Login successful");
                try {Thread.sleep(250);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                Intent login = new Intent(LogIn.this, ChatService.class);
                startActivity(login);

            } else {
                Log.w("HttpPost", "FALSE");
                result.setText(str);
            }

        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private StringBuilder inputStreamToString(InputStream is) {
        String line = "";
        StringBuilder total = new StringBuilder();
        // Wrap a BufferedReader around the InputStream
        BufferedReader rd = new BufferedReader(new InputStreamReader(is));
        // Read response until the end
        try {
            while ((line = rd.readLine()) != null) {
                total.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Return full string
        return total;
    }

    public void onClick(View view) {
        if (view == ok) {

            postLoginData();
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(pword.getWindowToken(), 0);
        }
        // Click end
    }
    // if statement
}

// class ends here
  • 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-01T09:47:28+00:00Added an answer on June 1, 2026 at 9:47 am

    Check for null:

    Bundle gotData = getIntent().getExtras();
    if(gotData != null)
    {
        GotPass = gotData.getString("key!");
        GotUname = gotData.getString("key!!");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Specifically, suppose I start with the string string =hello \'i am \' me And
I am trying to render a haml file in a javascript response like so:

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.