Я пытаюсь поместить кнопку в представление вкладки на Android. Все компилируется и собирается хорошо, но приложение не запускается. MenuActivity - это действие определенной вкладки, называемое виджетом «Меню вкладок».
Это мой код:
package ru.infolizard.medinfo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MenuActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
Button button = (Button)this.findViewById(R.id.buttonSearch);
button.setOnClickListener(new OnClickListener () {
public void onClick(View v) {
//Toast.makeText(MenuActivity.this, "Menu pressed", Toast.LENGTH_SHORT).show();
}
});
}
}
Это LogCat:
02-03 17:58:41.255: E/AndroidRuntime(1065): FATAL EXCEPTION: main
02-03 17:58:41.255: E/AndroidRuntime(1065): java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.infolizard.medinfo/ru.infolizard.medinfo.MedInfoTabWidgetActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.infolizard.medinfo/ru.infolizard.medinfo.MenuActivity}: java.lang.NullPointerException
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.os.Handler.dispatchMessage(Handler.java:99)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.os.Looper.loop(Looper.java:137)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-03 17:58:41.255: E/AndroidRuntime(1065): at java.lang.reflect.Method.invokeNative(Native Method)
02-03 17:58:41.255: E/AndroidRuntime(1065): at java.lang.reflect.Method.invoke(Method.java:511)
02-03 17:58:41.255: E/AndroidRuntime(1065): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-03 17:58:41.255: E/AndroidRuntime(1065): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-03 17:58:41.255: E/AndroidRuntime(1065): at dalvik.system.NativeStart.main(Native Method)
02-03 17:58:41.255: E/AndroidRuntime(1065): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.infolizard.medinfo/ru.infolizard.medinfo.MenuActivity}: java.lang.NullPointerException
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1797)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:682)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.widget.TabHost.setCurrentTab(TabHost.java:346)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.widget.TabHost.addTab(TabHost.java:236)
02-03 17:58:41.255: E/AndroidRuntime(1065): at ru.infolizard.medinfo.MedInfoTabWidgetActivity.onCreate(MedInfoTabWidgetActivity.java:29)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.Activity.performCreate(Activity.java:4465)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-03 17:58:41.255: E/AndroidRuntime(1065): ... 11 more
02-03 17:58:41.255: E/AndroidRuntime(1065): Caused by: java.lang.NullPointerException
02-03 17:58:41.255: E/AndroidRuntime(1065): at ru.infolizard.medinfo.MenuActivity.onCreate(MenuActivity.java:18)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.Activity.performCreate(Activity.java:4465)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-03 17:58:41.255: E/AndroidRuntime(1065): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-03 17:58:41.255: E/AndroidRuntime(1065): ... 21 more
Если я прокомментирую все, что касается кнопки, она работает нормально.