New Android Series - Tutorial # 22 Homework app crashing on launch

0 Sohaib Furqan · October 11, 2016
Hi all. I'm on Tutorial#22 of the android series for beginners by Bucky, and I was trying to code for the challenge he gave. My issue is that when I run the app on the emulator, it crashes and a messagebox with a "Force Close" button appears on the phone. 
The following is my code. I'd appreciate if any of you can tell me what's causing the app to crash without running. Regards. 


package com.bubblesoftweb.gestureshomeworlk; 

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 
import android.view.MotionEvent; 
import android.view.GestureDetector; 
import android.support.v4.view.GestureDetectorCompat; 

public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener{ 


Button buckysButton = (Button)findViewById(R.id.buckysBtn); 
TextView buckysMsg = (TextView)findViewById(R.id.buckysMessage); 
GestureDetectorCompat gestureDetector; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 

this.gestureDetector = new GestureDetectorCompat(this,this); 



buckysButton.setOnClickListener( 
new Button.OnClickListener() 

public void onClick(View v) 

buckysMsg.setText("I just got clicked!"); 



); 







@Override 
public boolean onDown(MotionEvent e) { 
return false; 


@Override 
public void onShowPress(MotionEvent e) { 



@Override 
public boolean onSingleTapUp(MotionEvent e) { 
return false; 


@Override 
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { 
buckysMsg.setText("Text changed due to onScroll Gesture "); 
return true; 


@Override 
public void onLongPress(MotionEvent e) { 



@Override 
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 
buckysMsg.setText("Text changed due to onFling Gesture "); 
return true; 


@Override 
public boolean onTouchEvent(MotionEvent event) { 
this.onTouchEvent(event); 
return super.onTouchEvent(event); 



Post a Reply

Replies

Oldest  Newest  Rating
0 Gary Whitney · October 12, 2016
The most important information you can provide me is the Error message in the run window of Android Studio.
It will point you to the line of code  that causes it to crash.
Short of that I would have to start a new project and paste your code while guessing at the manifest and layout file.
  • 1

Java / Android Development

131,138 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator