Note that there are some explanatory texts on larger screens.

plurals
  1. POActivity Intent not launched
    text
    copied!<p>In my application the main activity is launched but on button click the second activity is not launched via intent.</p> <p>This is my log cat entry</p> <pre><code>08-21 23:29:35.568: D/dalvikvm(680): GC_EXTERNAL_ALLOC freed 47K, 53% free 2544K/5379K, external 716K/1038K, paused 272ms 08-21 23:29:36.319: D/TimesheetMgmt Log(680): --&gt;Main activity launched. 08-21 23:29:53.908: D/TimesheetMgmt Log(680): --&gt;New Task button clicked. 08-21 23:29:54.128: D/AndroidRuntime(680): Shutting down VM 08-21 23:29:54.128: W/dalvikvm(680): threadid=1: thread exiting with uncaught exception (group=0x40015560) 08-21 23:29:54.198: E/AndroidRuntime(680): FATAL EXCEPTION: main 08-21 23:29:54.198: E/AndroidRuntime(680): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.timesheetmgmt/com.timesheetmgmt.NewTaskActivity}: java.lang.NullPointerException 08-21 23:29:54.198: E/AndroidRuntime(680): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569) 08-21 23:29:54.198: E/AndroidRuntime(680): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 08-21 23:29:54.198: E/AndroidRuntime(680): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 08-21 23:29:54.198: E/AndroidRuntime(680): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 08-21 23:29:54.198: E/AndroidRuntime(680): at android.os.Handler.dispatchMessage(Handler.java:99) 08-21 23:29:54.198: E/AndroidRuntime(680): at android.os.Looper.loop(Looper.java:123) 08-21 23:29:54.198: E/AndroidRuntime(680): at android.app.ActivityThread.main(ActivityThread.java:3683) 08-21 23:29:54.198: E/AndroidRuntime(680): at java.lang.reflect.Method.invokeNative(Native Method) 08-21 23:29:54.198: E/AndroidRuntime(680): at java.lang.reflect.Method.invoke(Method.java:507) 08-21 23:29:54.198: E/AndroidRuntime(680): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 08-21 23:29:54.198: E/AndroidRuntime(680): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 08-21 23:29:54.198: E/AndroidRuntime(680): at dalvik.system.NativeStart.main(Native Method) 08-21 23:29:54.198: E/AndroidRuntime(680): Caused by: java.lang.NullPointerException 08-21 23:29:54.198: E/AndroidRuntime(680): at android.app.Activity.findViewById(Activity.java:1647) 08-21 23:29:54.198: E/AndroidRuntime(680): at com.timesheetmgmt.NewTaskActivity.&lt;init&gt;(NewTaskActivity.java:16) 08-21 23:29:54.198: E/AndroidRuntime(680): at java.lang.Class.newInstanceImpl(Native Method) 08-21 23:29:54.198: E/AndroidRuntime(680): at java.lang.Class.newInstance(Class.java:1409) 08-21 23:29:54.198: E/AndroidRuntime(680): at android.app.Instrumentation.newActivity(Instrumentation.java:1021) 08-21 23:29:54.198: E/AndroidRuntime(680): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561) 08-21 23:29:54.198: E/AndroidRuntime(680): ... 11 more 08-21 23:29:58.879: I/Process(680): Sending signal. PID: 680 SIG: 9 </code></pre> <p>Main Activity code:</p> <pre><code> package com.timesheetmgmt; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity implements OnClickListener{ private static final String DEBUG_TAG= "TimesheetMgmt Log"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.d(DEBUG_TAG, "--&gt;Main activity launched. "); Button btnNewTask=(Button) findViewById(R.id.btnNewTask); btnNewTask.setOnClickListener((OnClickListener) this); } public void onClick(View v) { if(v.getId()==R.id.btnNewTask){ try { Log.d(DEBUG_TAG, "--&gt;New Task button clicked. "); Intent in=new Intent(this,NewTaskActivity.class); in.putExtra("str", "jjalj new task activity"); startActivity(in); } catch (Exception e) { e.printStackTrace(); } } } } </code></pre> <p>in log cat file i can see main activity launched and when i click the new task button the error as mentioned above in log cat and force close button comes on emulator.</p>
 

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