Note that there are some explanatory texts on larger screens.

plurals
  1. POExample from a tutorial crashes with NullPointerException
    primarykey
    data
    text
    <p>I have completed the email application that is taught by The New Boston site. As far as I have reviewed, everything is fine. My app runs just fine, but just when I press the <code>"Send Email"</code> <code>Button</code>, the app crashes. I am testing the app on my <code>HTC Desire S</code>. Please help me with this. </p> <p>My manifest file:</p> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.thenewboston.pok" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /&gt; &lt;uses-permission android:name="android.permission.SET_WALLPAPER"/&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name=".Splash" android:label="@string/title_activity_the_new_boston" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".TheNewBostonActivity" android:label="Add and Sub 1" &gt; &lt;intent-filter&gt; &lt;action android:name="com.thenewboston.pok.THENEWBOSTONACTIVITY" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".Menu" android:label="Select An Application" &gt; &lt;intent-filter&gt; &lt;action android:name="com.thenewboston.pok.MENU" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".TextPlay" android:label="Text Play!" &gt; &lt;/activity&gt; &lt;activity android:name=".Email" android:label="Email Application" &gt; &lt;intent-filter&gt; &lt;action android:name="com.thenewboston.pok.EMAIL" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".Camera" android:label="Camera Application" android:screenOrientation="portrait" &gt; &lt;/activity&gt; &lt;activity android:name=".Data" android:label="Rate It!!" android:screenOrientation="portrait" &gt; &lt;/activity&gt; &lt;activity android:name=".OpenedClass" android:label="Rate It!!" android:screenOrientation="portrait" &gt; &lt;/activity&gt; &lt;/application&gt; </code></pre> <p></p> <p>The <code>Email</code> activity:</p> <pre><code>public class Email extends Activity implements View.OnClickListener{ EditText personsEmail, intro, personsName, stupidThings, hatefulAction, outro; String emailAdd, beginning, name, stupidAction, hateAct, end; Button sendEmail; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.email); initializeVars(); sendEmail.setOnClickListener(this); } private void initializeVars() { // TODO Auto-generated method stub personsEmail = (EditText) findViewById(R.id.etEmails); stupidThings = (EditText) findViewById(R.id.etThings); intro = (EditText) findViewById(R.id.etIntro); personsName= (EditText) findViewById(R.id.etName); hatefulAction= (EditText) findViewById(R.id.etAction); sendEmail= (Button) findViewById(R.id.bSentEmail); } public void onClick(View v) { // TODO Auto-generated method stub convertEditToString(); String emailAddress[] = {"emailAdd"}; String message = "Well hello " + name + " I just wanted to say " + beginning + ". Not only that but I hate when you " + stupidAction + ", that just really makes me crazy. I just want to make you " + hateAct + ". Welp, thats all I wanted to chit-chatter about, oh and " + end + ". Oh also if you get bored you should check out www.mybringback.com" + '\n' + "PS. I think I love you... :-( "; Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailAddress); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hello"); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message); startActivity (emailIntent); } private void convertEditToString() { // TODO Auto-generated method stub emailAdd = personsEmail.getText().toString(); beginning = intro.getText().toString(); name = personsName.getText().toString(); hateAct = hatefulAction.getText().toString(); stupidAction = stupidThings.getText().toString(); end = outro.getText().toString(); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); finish(); } } </code></pre> <p>My <em>email.xml</em>:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:weightSum="100" android:layout_height="match_parent"&gt; &lt;ScrollView android:layout_weight="30" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;TextView android:text="Email address(es):" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/TextView&gt; &lt;EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/etEmails"&gt; &lt;/EditText&gt; &lt;TextView android:text="Hateful Intro:" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/TextView&gt; &lt;EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/etIntro"&gt;&lt;/EditText&gt; &lt;TextView android:text="Person's name" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/TextView&gt; &lt;EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/etName"&gt;&lt;/EditText&gt; &lt;TextView android:text="Stupid Things that this Person does" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/TextView&gt; &lt;EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/etThings"&gt;&lt;/EditText&gt; &lt;TextView android:text="What you want to do to this person:" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/TextView&gt; &lt;EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/etAction"&gt;&lt;/EditText&gt; &lt;TextView android:text="Hateful Outro" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/TextView&gt; &lt;EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/etOutro"&gt;&lt;/EditText&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; &lt;LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_weight="40" android:layout_height="fill_parent"&gt; &lt;Button android:text="Send Email" android:id="@+id/bSentEmail" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt;&lt;/Button&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_weight="30" android:layout_height="fill_parent"&gt; &lt;AnalogClock android:id="@+id/analogClock1" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt;&lt;/AnalogClock&gt; &lt;/LinearLayout&gt; </code></pre> <p></p> <p>The <code>LogCat</code> with the <code>NullPointerException</code>:</p> <pre><code>10-02 22:15:40.603: E/AndroidRuntime(28009): FATAL EXCEPTION: main 10-02 22:15:40.603: E/AndroidRuntime(28009): java.lang.NullPointerException 10-02 22:15:40.603: E/AndroidRuntime(28009): at com.thenewboston.pok.Email.convertEditToString(Email.java:69) 10-02 22:15:40.603: E/AndroidRuntime(28009): at com.thenewboston.pok.Email.onClick(Email.java:38) 10-02 22:15:40.603: E/AndroidRuntime(28009): at android.view.View.performClick(View.java:3549) 10-02 22:15:40.603: E/AndroidRuntime(28009): at android.view.View$PerformClick.run(View.java:14393) 10-02 22:15:40.603: E/AndroidRuntime(28009): at android.os.Handler.handleCallback(Handler.java:605) 10-02 22:15:40.603: E/AndroidRuntime(28009): at android.os.Handler.dispatchMessage(Handler.java:92) 10-02 22:15:40.603: E/AndroidRuntime(28009): at android.os.Looper.loop(Looper.java:154) 10-02 22:15:40.603: E/AndroidRuntime(28009): at android.app.ActivityThread.main(ActivityThread.java:4945) 10-02 22:15:40.603: E/AndroidRuntime(28009): at java.lang.reflect.Method.invokeNative(Native Method) 10-02 22:15:40.603: E/AndroidRuntime(28009): at java.lang.reflect.Method.invoke(Method.java:511) 10-02 22:15:40.603: E/AndroidRuntime(28009): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 10-02 22:15:40.603: E/AndroidRuntime(28009): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 10-02 22:15:40.603: E/AndroidRuntime(28009): at dalvik.system.NativeStart.main(Native Method) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload