This Null Pointer Exception is because your resource is not loaded properly try to clean project and run again will resolve.
R.id.run_time this is loaded from R.java which is auto generated file. Clean and rebuilt project will fix this.
MainActivity.java
package com.example.stacktest;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView run_time = (TextView) findViewById(R.id.run_time);
try {
run_time.setText("t");
}catch(Exception e) {
Log.i("Log", e.getMessage()+"Error!"); // LogCat message
}
}
}
and activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/run_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ghjghjghjghjghjghj" />
</LinearLayout>