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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:43:01+00:00 2026-06-08T20:43:01+00:00

I started programmig Android App. But I’m struggling with this, despite I found something

  • 0

I started programmig Android App. But I’m struggling with this, despite I found something similar out on this forum (here -yet checked-). My app crashes when I press the button.
here the code:

package mobileapp;

import android.app.Activity;
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 MainActivity extends Activity implements OnClickListener {

  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      View button = (Button) findViewById(R.id.button_print_string);
      button.setOnClickListener(this);
  }

  public void onClick(View v) {
      switch (v.getId()) {
      case R.id.button_print_string:
              EditText cerca = (EditText) findViewById(R.id.cerca);
          Bundle bundle = new Bundle();
          bundle.putString("result", cerca.getText().toString());
          Intent Intent2 = new Intent(getApplicationContext(), SecondActivity.class);
          startActivity(Intent2);
      }
  }

}

here my manifest_file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.stasbranger.clinigomobile"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>

     <activity
        android:name=".SecondActivity" >
        <intent-filter ></intent-filter>
     </activity>
</application>

</manifest>

and my activity_main:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >


<Button
    android:id="@+id/button_print_string"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:text="@string/str_button" />

<EditText android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/cerca" 
    android:inputType="textEmailAddress" 
    android:text="@string/cerca">
<requestFocus></requestFocus>
</EditText>



</RelativeLayout>

I get:

08-01 09:40:59.335: E/AndroidRuntime(560): FATAL EXCEPTION: main
08-01 09:40:59.335: E/AndroidRuntime(560): java.lang.RuntimeException: Unable to start activity ComponentInfo{it.stasbranger.clinigomobile/it.stasbranger.clinigomobile.SecondActivity}: java.lang.NullPointerException
08-01 09:40:59.335: E/AndroidRuntime(560):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-01 09:40:59.335: E/AndroidRuntime(560):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-01 09:40:59.335: E/AndroidRuntime(560):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-01 09:40:59.335: E/AndroidRuntime(560):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-01 09:40:59.335: E/AndroidRuntime(560):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 09:40:59.335: E/AndroidRuntime(560):  at android.os.Looper.loop(Looper.java:137)
08-01 09:40:59.335: E/AndroidRuntime(560):  at android.app.ActivityThread.main(ActivityThread.java:4424)
08-01 09:40:59.335: E/AndroidRuntime(560):  at java.lang.reflect.Method.invokeNative(Native Method)
08-01 09:40:59.335: E/AndroidRuntime(560):  at java.lang.reflect.Method.invoke(Method.java:511)
08-01 09:40:59.335: E/AndroidRuntime(560):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-01 09:40:59.335: E/AndroidRuntime(560):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-01 09:40:59.335: E/AndroidRuntime(560):  at dalvik.system.NativeStart.main(Native Method)
08-01 09:40:59.335: E/AndroidRuntime(560): Caused by: java.lang.NullPointerException
08-01 09:40:59.335: E/AndroidRuntime(560):  at it.stasbranger.clinigomobile.SecondActivity.onCreate(SecondActivity.java:14)
08-01 09:40:59.335: E/AndroidRuntime(560):  at android.app.Activity.performCreate(Activity.java:4465)
08-01 09:40:59.335: E/AndroidRuntime(560):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-01 09:40:59.335: E/AndroidRuntime(560):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-01 09:40:59.335: E/AndroidRuntime(560):  ... 11 more

suggestions?

  • 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-08T20:43:02+00:00Added an answer on June 8, 2026 at 8:43 pm

    You are getting NullPointerException because, you have not used setContentView method.

    public class SecondActivity extends Activity {
    TextView text_result; ?? DECLARATION

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.second_activity_xml);  //  CREATE XML ADD  THIS
    
        Bundle bundle = this.getIntent().getExtras();
    
        text_result = (TextView) findViewViewById(R.id.text_resultID);  //  INITIALIZE
        text_result.setText(bundle.getString("result"));
    }
    

    }

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

Sidebar

Related Questions

This started out as a general user question on Android forums. However it's become,
I'm new to Android app programming and started to read a book, but it
Hello! I've been programming for a long time but just started developing for android,
Recently started programming Android Java (Eclipse), Im trying to make a simple reader app
This is my first question at stackoverflow :-). However, I've started to Android programming
I've started Android programming recently so bear with me :) I develop an app
I have just recently started out programming for Android, and have decided that I
i'm currently developing an app for both Android and iOS, thing is... I started
This is my first post, and I've only recently started programming for Android and
Hey everyone! Started programming with Bluetooth on Android awhile ago. But now I've run

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.