24 Oct 2012, 20:43
Generic-user-small

Daniel Grabovskiy (3 posts)

First i want to say, please update the book, most of the codes are outdated, and/or have been changed/modified. Thank you

second public void onClick (View v) { error> swtich (v.getId()){ error> case R.id.about_button: Intent i = new Intent(this, About.class); startActivity(i); break;

here is what the errors are 1.Syntax error on token(s), misplaced construct(s) 2.Syntax error on tokens, delete these tokens 3.Syntax error on token “:”, { expected after this token

how do you fix that

25 Oct 2012, 07:56
Generic-user-small

wang jh (1 post)

very good thanks

25 Oct 2012, 12:03
Generic-user-small

Daniel Grabovskiy (3 posts)

what? i asked how to fix this. im running into this error. im a highschool student trying to make an android launcher by april 2013 and im using this for practice and research. these are some really weird errors i have never seen in java files, ever.

25 Oct 2012, 15:21
Generic-user-small

Anthony Shaw (132 posts)

Post a bit more of the code the problem is probably in there somewhere, unless the word ‘second’ before ‘public void onClick’ is really in your source code in which case remove it and see how many problems that fixes.

This looks like the code from page 48 or so, again if that is the case make sure that the rest of the code for About.java has been entered correctly.

02 Nov 2012, 17:13
Generic-user-small

Daniel Grabovskiy (3 posts)

package com.yolo.sudoku;

import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.content.Intent;

public class MainActivity extends Activity implements OnClickListener {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
    
public void OnCreate (Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	View continueButton = findViewById(R.id.continue_button);
	continueButton.setOnClickListener((OnClickListener) this);
	View newButton = findViewById(R.id.new_button);
	newButton.setOnClickListener((OnClickListener) this);
	View aboutButton = findViewById(R.id.about_button);
	aboutButton.setOnClickListener((OnClickListener) this);
	View exitButton = findViewById(R.id.exit_button);
	exitButton.setOnClickListener((OnClickListener) this);
	}

public void onClick (View v) {
	swtich (v.getId()){
	case R.id.about_button:
		Intent i = new Intent(this, About.class);
		startActivity(i);
		break;
		//more buttons go here if any
		}

} }

may be the book is outdated

03 Nov 2012, 17:17
Generic-user-small

Anthony Shaw (132 posts)

The keyword ‘switch’ is wrong after the line ‘public void onClick’, you have got the ‘t’ and the ‘i’ the wrong way round. Try correcting that and running again.

I don’t think the book is too out of date and the code runs if it is typed in correctly in my experience.

13 Apr 2013, 21:19
Burnette_ed_pragsmall

Ed Burnette (1316 posts)

The book assumes some experience in Java or a similar language. If you’re completely new to Java try one of the books listed here:

  • http://forums.pragprog.com/forums/138/topics/3679
  You must be logged in to comment