0

I have just started to learn how to program android apps, And im a COMPLETE NOOB. I cant figure out how to fix this! please help! The format may look butchered... It's cause i have no clue what im doing!

    package com.smiggle.bmxhandbook;

     import android.os.Bundle;
     import android.app.Activity;
     import android.view.Menu;

    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.content.Intent;

      public class MainActivity extends Activity {

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


        Button button;

    public void onCreate1(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        addListenerOnButton();
    }
    public void addListenerOnButton() {

        button = (Button) findViewById(R.id.button1);

        button.setOnClickListener(new OnClickListener() {

            public void onClick1(View arg0) { 

                Intent myIntent = new Intent(MainActivity.this, Trick.class           
                MainActivity.this.startActivity(myIntent);

            }

            public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub; }

    }

It keeps on giving me a syntax error!

2 Answers 2

1

Try this code instead:

public class MainActivity extends Activity {

    Button button;

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

        addListenerOnButton();
    }

    public void addListenerOnButton() {

        button = (Button) findViewById(R.id.button1);

        button.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) { 

                Intent myIntent = new Intent(MainActivity.this, Trick.class);      
                MainActivity.this.startActivity(myIntent);
            }
        });
    }       

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}

Your class had a ridiculously high amount of syntax and logical errors:

  • Arbitrary onCreate1() method, which will never me called.
  • Arbitrary onClick() method, even though your Activity never implemented the interface
  • Your anonymous inner class' onClick() method was named onClick1()
  • The statement with the Intent was missing a ); at the end.
  • The inner class body was missing a closing });
  • The addListenerOnButton() method was missing a closing }
  • Your entire class was missing a closing }

I sincerely recommend you spend a few months (or even a year) learning Java before coming to Android.

Sign up to request clarification or add additional context in comments.

Comments

0

You have this wide open

Intent myIntent = new Intent(MainActivity.this, Trick.class 

You need to close that with a right parenthesis and and a semicolon.

Also that onClick should not have a 1 in it:

public void onClick1(View arg0) {

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.