So I created a new project via Eclipse ADT and my app won't run, here is some useful info about it. I would be very grateful if you'd solve it.
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 TextView answer = (TextView) findViewById(R.id.textView1);
Button askButton = (Button) findViewById(R.id.button1);
askButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
answer.setText("veik");
}
});
}
This is the only part of MainActivity.java that was edited, here is the edited part of xml file:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Button" />
And lastly, message of LogCat:
06-19 00:04:56.740: D/AndroidRuntime(7026): Shutting down VM
06-19 00:04:56.740: W/dalvikvm(7026): threadid=1: thread exiting with uncaught exception (group=0x41760ba8)
06-19 00:04:56.740: E/AndroidRuntime(7026): FATAL EXCEPTION: main
06-19 00:04:56.740: E/AndroidRuntime(7026): Process: com.example.babyplease, PID: 7026
06-19 00:04:56.740: E/AndroidRuntime(7026): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.babyplease/com.example.babyplease.MainActivity}: java.lang.NullPointerException
06-19 00:04:56.740: E/AndroidRuntime(7026): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
06-19 00:04:56.740: E/AndroidRuntime(7026): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2248)
06-19 00:04:56.740: E/AndroidRuntime(7026): at android.app.ActivityThread.access$800(ActivityThread.java:138)
06-19 00:04:56.740: E/AndroidRuntime(7026): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
06-19 00:04:56.740: E/AndroidRuntime(7026): at android.os.Handler.dispatchMessage(Handler.java:102)
06-19 00:04:56.740: E/AndroidRuntime(7026): at android.os.Looper.loop(Looper.java:136)
06-19 00:04:56.740: E/AndroidRuntime(7026): at android.app.ActivityThread.main(ActivityThread.java:5050)
06-19 00:04:56.740: E/AndroidRuntime(7026): at java.lang.reflect.Method.invokeNative(Native Method)
06-19 00:04:56.740: E/AndroidRuntime(7026): at java.lang.reflect.Method.invoke(Method.java:515)
06-19 00:04:56.740: E/AndroidRuntime(7026): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
06-19 00:04:56.740: E/AndroidRuntime(7026): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
06-19 00:04:56.740: E/AndroidRuntime(7026): at dalvik.system.NativeStart.main(Native Method)
06-19 00:04:56.740: E/AndroidRuntime(7026): Caused by: java.lang.NullPointerException
06-19 00:04:56.740: E/AndroidRuntime(7026): at com.example.babyplease.MainActivity.onCreate(MainActivity.java:31)
06-19 00:04:56.740: E/AndroidRuntime(7026): at android.app.Activity.performCreate(Activity.java:5241)
06-19 00:04:56.740: E/AndroidRuntime(7026): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-19 00:04:56.740: E/AndroidRuntime(7026): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
06-19 00:04:56.740: E/AndroidRuntime(7026): ... 11 more
06-19 00:04:59.365: I/Process(7026): Sending signal. PID: 7026 SIG: 9
Sorry if there is too much text, I'm just very confused why doesn't it work.