Last active
October 8, 2018 09:51
-
-
Save MwBakker/5669b8bcd1a11882effb7490659f8a06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Works // | |
public class MainActivity extends AppCompatActivity { | |
// ... | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); | |
ClickHandlers handlers = new ClickHandlers(MainActivity.this); | |
binding.setHandlers(handlers); | |
fab.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
Intent intent = new Intent(MainActivity.this, NewWordActivity.class); | |
startActivityForResult(intent, NEW_WORD_ACTIVITY_REQUEST_CODE); | |
} | |
}); | |
// ... | |
} | |
=========================================================== | |
// Does not work // | |
" java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference " | |
@Line 40 (in this matter) | |
public class ClickHandlers extends Activity { | |
Context context; | |
public void fabClicked(View view) { | |
Intent intent = new Intent(context, NewWordActivity.class); | |
startActivityForResult(intent, NEW_WORD_ACTIVITY_REQUEST_CODE); | |
} | |
} | |
=========================================================== | |
<android.support.design.widget.FloatingActionButton | |
// ... | |
android:onClick="@{handlers.fabClicked}" | |
// ... /> |
RaghavSood
commented
Oct 8, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment