[Java for Android App Development] rockstar283:
I am just taking baby steps in learning Android programming..I am following some tutorials for that and while studying how to implement onKeyListener I am getting an error 'java.lang.RuntimeException: Unable to instantiate activity ComponentInfo java.lang.NullPointerException'. This error is leading to another error 'adt unfortunately app has stopped' while trying to run the app on my phone. Here is the logcat:

05-15 15:55:22.087: D/AndroidRuntime(20672): Shutting down VM

05-15 15:55:22.087: W/dalvikvm(20672): threadid=1: thread exiting with uncaught exception (group=0x41ea1ba8)

05-15 15:55:22.087: E/AndroidRuntime(20672): FATAL EXCEPTION: main

05-15 15:55:22.087: E/AndroidRuntime(20672): Process: com.example.keyboardlistener, PID: 20672

05-15 15:55:22.087: E/AndroidRuntime(20672): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.keyboardlistener/com.example.keyboardlistener.MainActivity}: java.lang.NullPointerException

05-15 15:55:22.087: E/AndroidRuntime(20672):	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at android.app.ActivityThread.access$800(ActivityThread.java:135)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at android.os.Handler.dispatchMessage(Handler.java:102)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at android.os.Looper.loop(Looper.java:136)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at android.app.ActivityThread.main(ActivityThread.java:5017)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at java.lang.reflect.Method.invokeNative(Native Method)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at java.lang.reflect.Method.invoke(Method.java:515)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at dalvik.system.NativeStart.main(Native Method)

05-15 15:55:22.087: E/AndroidRuntime(20672): Caused by: java.lang.NullPointerException

05-15 15:55:22.087: E/AndroidRuntime(20672):	at android.app.Activity.findViewById(Activity.java:1884)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at com.example.keyboardlistener.MainActivity.<init>(MainActivity.java:18)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at java.lang.Class.newInstanceImpl(Native Method)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at java.lang.Class.newInstance(Class.java:1208)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at android.app.Instrumentation.newActivity(Instrumentation.java:1061)

05-15 15:55:22.087: E/AndroidRuntime(20672):	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)

05-15 15:55:22.087: E/AndroidRuntime(20672):	... 11 more

05-15 16:00:21.837: I/dalvikvm(22483): Debugger is active

05-15 16:00:21.847: I/System.out(22483): Debugger has connected

05-15 16:00:21.857: I/System.out(22483): waiting for debugger to settle...

05-15 16:00:22.057: I/System.out(22483): waiting for debugger to settle...

05-15 16:00:22.257: I/System.out(22483): waiting for debugger to settle...

05-15 16:00:22.457: I/System.out(22483): waiting for debugger to settle...

05-15 16:00:22.657: I/System.out(22483): waiting for debugger to settle...

05-15 16:00:22.857: I/System.out(22483): waiting for debugger to settle...

05-15 16:00:23.057: I/System.out(22483): waiting for debugger to settle...

05-15 16:00:23.257: I/System.out(22483): waiting for debugger to settle...

05-15 16:00:23.457: I/System.out(22483): debugger has settled (1495)

05-15 16:00:23.797: D/dalvikvm(22483): threadid=1: still suspended after undo (sc=1 dc=1)

05-15 16:09:43.367: D/AndroidRuntime(24025): Shutting down VM

05-15 16:09:43.367: W/dalvikvm(24025): threadid=1: thread exiting with uncaught exception (group=0x41ea1ba8)

05-15 16:09:43.367: E/AndroidRuntime(24025): FATAL EXCEPTION: main

05-15 16:09:43.367: E/AndroidRuntime(24025): Process: com.example.keyboardlistener, PID: 24025

05-15 16:09:43.367: E/AndroidRuntime(24025): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.keyboardlistener/com.example.keyboardlistener.MainActivity}: java.lang.NullPointerException

05-15 16:09:43.367: E/AndroidRuntime(24025):	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)

05-15 16:09:43.367: E/AndroidRuntime(24025):	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)

05-15 16:09:43.367: E/AndroidRuntime(24025):	at android.app.ActivityThread.access$800(ActivityThread.java:135)

05-15 16:09:43.367: E/AndroidRuntime(24025):	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)

05-15 16:09:43.367: E/AndroidRuntime(24025):	at android.os.Handler.dispatchMessage(Handler.java:102)

05-15 16:09:43.367: E/AndroidRuntime(24025):	at android.os.Looper.loop(Looper.java:136)

05-15 16:09:43.367: E/AndroidRuntime(24025):	at android.app.ActivityThread.main(ActivityThread.java:5017)

05-15 16:09:43.367: E/AndroidRuntime(24025):	at java.lang.reflect.Method.invokeNative(Native Method)

05-15 16:09:43.367: E/AndroidRuntime(24025):	at java.lang.reflect.Method.invoke(Method.java:515)

05-15 16:09:43.367: E/AndroidRuntime(24025):	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)

05-15 16:09:43.367: E/AndroidRuntime(24025):	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)

05-15 16:09:43.367: E/AndroidRuntime(24025):	at dalvik.system.NativeStart.main(Native Method)

05-15 16:09:43.367: E/AndroidRuntime(24025): Caused by: java.lang.NullPointerException

05-15 16:09:43.367: E/AndroidRuntime(24025):	at com.example.keyboardlistener.MainActivity.onCreate(MainActivity.java:35)

05-15 16:09:43.367: E/AndroidRuntime(24025):	at android.app.Activity.performCreate(Activity.java:5231)

05-15 16:09:43.367: E/AndroidRuntime(24025):	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)

05-15 16:09:43.367: E/AndroidRuntime(24025):	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)

05-15 16:09:43.367: E/AndroidRuntime(24025):	... 11 more

And here is the onCreate method:

[MENTION=439709]override[/MENTION]

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

if (savedInstanceState == null) {

getSupportFragmentManager().beginTransaction()

.add(R.id.container, new PlaceholderFragment())

.commit();

}

final EditText ed = (EditText)findViewById(R.id.editTextUserEntry1);

final TextView tv = (TextView)findViewById(R.id.TextResults);

ed.setOnKeyListener(new OnKeyListener(){

[MENTION=439709]override[/MENTION]

public boolean onKey(View v, int keyCode, KeyEvent event) {

// TODO Auto-generated method stub

if(event.getAction()==KeyEvent.ACTION_DOWN)

{

if(keyCode == KeyEvent.KEYCODE_ENTER)

{

tv.setText(ed.getText());

}

}

return false;

}

});

}