Код: Выделить всё
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
TextView text_hello;
Button but_hi;
@Override
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();
}
text_hello = (TextView) findViewById(R.id.text_hello);
but_hi = (Button) findViewById(R.id.but_hi);
OnClickListener clickbut = new OnClickListener() {
@Override
public void onClick(View v) {
text_hello.setText("ololo");
}
};
but_hi.setOnClickListener(clickbut);
}
- 05-08 17:25:14.186: W/dalvikvm(9202): threadid=1: thread exiting with uncaught exception (group=0x40be3378)
05-08 17:25:14.196: E/AndroidRuntime(9202): FATAL EXCEPTION: main
05-08 17:25:14.196: E/AndroidRuntime(9202): java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.hellknight.helloworld/ru.hellknight.helloworld.MainActivity}: java.lang.NullPointerException
05-08 17:25:14.196: E/AndroidRuntime(9202): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071)
05-08 17:25:14.196: E/AndroidRuntime(9202): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
05-08 17:25:14.196: E/AndroidRuntime(9202): at android.app.ActivityThread.access$600(ActivityThread.java:138)
05-08 17:25:14.196: E/AndroidRuntime(9202): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
05-08 17:25:14.196: E/AndroidRuntime(9202): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 17:25:14.196: E/AndroidRuntime(9202): at android.os.Looper.loop(Looper.java:213)
05-08 17:25:14.196: E/AndroidRuntime(9202): at android.app.ActivityThread.main(ActivityThread.java:4787)
05-08 17:25:14.196: E/AndroidRuntime(9202): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 17:25:14.196: E/AndroidRuntime(9202): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 17:25:14.196: E/AndroidRuntime(9202): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
05-08 17:25:14.196: E/AndroidRuntime(9202): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
05-08 17:25:14.196: E/AndroidRuntime(9202): at dalvik.system.NativeStart.main(Native Method)
05-08 17:25:14.196: E/AndroidRuntime(9202): Caused by: java.lang.NullPointerException
05-08 17:25:14.196: E/AndroidRuntime(9202): at ru.hellknight.helloworld.MainActivity.onCreate(MainActivity.java:37)
05-08 17:25:14.196: E/AndroidRuntime(9202): at android.app.Activity.performCreate(Activity.java:5008)
05-08 17:25:14.196: E/AndroidRuntime(9202): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-08 17:25:14.196: E/AndroidRuntime(9202): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
05-08 17:25:14.196: E/AndroidRuntime(9202): ... 11 more
05-08 17:25:15.426: I/Process(9202): Sending signal. PID: 9202 SIG: 9