views:

80

answers:

2

The code comes from "Hello Android" Page47. I am using 1.6 since that is what the book is written for.

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


    /** Called when the activity is first created. */

e1  @Override
e2  public void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState),
    setContentView(R.layout.main),
    // Set up click listeners for all the buttons

error message e1 the annotation @override is dissallowed for this location

error message e2 Multiple markers at this line - Syntax error on token(s), misplaced construct(s) - Syntax error on token "void", @ expected - Syntax error on token ")", = expected

I have no idea whats wrong. The code is identical to the code in the book. I'm sure. TIA

+1  A: 

Download the code from Hello Android's Official Website to get a for-sure working version. You can also check the errata.

DMan
+2  A: 

Firstly, are you sure the book is written for Java 1.6? I'm pretty sure Android is designed for 1.5 compatibility.

Anyway, the reason for both errors would appear to be that you have placed the onCreate method outside of a class body.

Between the import statements and the first comment, there should be a class declaration like:

public class MyActivity extends Activity
Christopher
and furthermore the class you plan to extend (say it's `Activity` here) must have a method named `onCreate` with an identical signature to override.
Mark E
Baleisen
I'm probably thinking of building the Android platform itself, which is (was?) 1.5 only. Anyway, just copying and pasting what I wrote above won't fix the code.. there's braces required at the start and end of the class etc. It might be beneficial to look at some Java tutorials before starting out with Android.
Christopher
The book wasn't clear as where to put that statement. I downloaded the code. But I am only using it when I can't figure out what is going on. I want to learn Droid Java. Thanks. I reloaded the SDK. It works now. Thanks to everybody.
Baleisen