Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing String error
    primarykey
    data
    text
    <p>I'm trying to pass a string from an activity to another. I went through many of the questions refering to "Intents" and "Passing strings" but I keep getting the same error. Could someone point me out where I'm mistaken? Here's my code</p> <p>First Activity</p> <pre><code> package com.example.youtube; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.text.Editable; import android.view.Menu; import android.widget.EditText; import android.widget.TextView; public class Testing extends Activity { public static String IPAddress = ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_testing); //Alert Popup AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Step 1"); alert.setMessage("Enter IP Address\n(i.e: 192.168.0.1)"); // Set an EditText view to get user input final EditText input = new EditText(this); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Editable value = input.getText(); // Do something with value! IPAddress = value.toString(); //Fire that second activity Intent intent = new Intent( getBaseContext(),LoginIn.class); intent.putExtra("keyword1",IPAddress); startActivity( intent); if (IPAddress != ""){ startActivity(new Intent("com.example.youtube.LoginIn")); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. finish(); System.exit(0); } }); alert.show(); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); } @Override protected void onPause() { // TODO Auto-generated method stub finish(); System.exit(0); } } </code></pre> <p>Second Activity</p> <pre><code> package com.example.youtube; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.app.Activity; import android.content.Intent; public class LoginIn extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); Button bverify = (Button) findViewById(R.id.verify1); final TextView testview = (TextView) findViewById(R.id.textView3); Bundle extras=getIntent().getExtras(); String value1=extras.getString("keyword1"); bverify.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub startActivity(new Intent("com.example.youtube.domotique")); } }); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); } @Override protected void onPause() { // TODO Auto-generated method stub finish(); System.exit(0); } } </code></pre> <p>Manifest</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.youtube" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name=".Testing" android:label="@string/app_name" &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=".LoginIn" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="com.example.youtube.LoginIn" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".domotique" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="com.example.youtube.domotique" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>Logcat</p> <pre><code> threadid=1: thread exiting with uncaught exception (group=0x40020ac0) FATAL EXCEPTION: main Unable to start activity ComponentInfo{com.example.youtube/com.example.youtube.LoginIn}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) at android.app.ActivityThread.access$2300(ActivityThread.java:125) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4627) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.example.youtube.LoginIn.onCreate(LoginIn.java:23) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) </code></pre> <p>I tried many form of Intent, and at different location in my code but my App keeps crashing when pressing "Ok", when my Second activity is launched.</p> <p>Thanks for any help!!</p>
    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.
 

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