small medium large xlarge

Generic-user-small
24 Oct 2012, 20:43
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

Generic-user-small
25 Oct 2012, 07:56
wang jh (1 post)

very good thanks

Generic-user-small
25 Oct 2012, 12:03
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.

Generic-user-small
25 Oct 2012, 15:21
Anthony Shaw (138 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.

Generic-user-small
02 Nov 2012, 17:13
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

Generic-user-small
03 Nov 2012, 17:17
Anthony Shaw (138 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.

Burnette_ed_pragsmall
13 Apr 2013, 21:19
Ed Burnette (1330 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