code errors copying from a book

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


Asked by: Aida788 | Posted: 25-01-2022






Answer 1

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

Answered by: Wilson436 | Posted: 26-02-2022



Answer 2

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

Answered by: Kellan167 | Posted: 26-02-2022



Similar questions

Copying a file off an android device?

How can I copy a file from some Android app's assets folder, to somewhere off the device? Alternatively, how can I move or copy an app so that it is installed on the sd card, not the main rom? Peter


android - copying view objects

I have a ListView that I am populating with LinearLayouts that contain one CheckBox apiece. The LinearLayout's are added dynamically for each object I am returning from a web service I have. I need for a user to be able to click a done button and for the application to go through the list of CheckBox's and update a database for each checked item. The database and the done button were a piece of cake, but obtaining a refe...


android - Copying generic .db files to sdcard

How can I copy a generic .db file (not part of my resources, like contacts.db) from the device filesystem to another location say sdcard? Can I use - InputStream ins = getResources().openRawResource("path to my .db file"); And then proceed as you showed above. Thanks in advance for your help


android - Copying an image, loses Exif data

I am copying an image to a private directory like so: FileChannel source = null; FileChannel destination = null; source = new FileInputStream(sourceFile).getChannel(); destination = new FileOutputStream(destFile).getChannel(); destination.transferFrom(source, 0, source.size()); source.close(); destination.close(); ..but when I insert it back in to Gallery, untouched, at a later time: ...


android - Copying Media Player Object

If I create a copy of a MediaPlayer object, which object will a callback function be called on. For example: MediaPlayer mp = new MediaPlayer(); MediaPlayer mp_copy = mp; mp.setOnBufferingUpdateListener(...); mp_copy.setOnBufferingUpdateListener(...); When the buffer is updated, which object will receive the callback (or will both of them)? Thanks.


android - Copying png file from a folder to another

I have a PNG file in a folder, I want to copy this file to another folder. Is there a easy way to do this ? Example: //Creating PNG File file = new File(Environment.getExternalStorageDirectory() + File.separator+"/S_Temp/temp_"+formattedDate+".png"); FileOutputStream out = new FileOutputStream(file); view.mBitmap.compress(Bitmap.CompressF...


android - Using icons from system versus copying them into your project

For common Android icons (such as context menu icons) I typically copy the standard Android icons into my project. I realized recently that you can also get those icons from the system using android.R.drawable.blablabla. So my question is, is there any reason to prefer one approach over the other? And if using the system ones is better, how do you access them in XML? Thanks!


android - Copying files from adb to window

Is there any way to copy files from the adb shell to another place in Windows?


android - Copying files from PC to tablet in a folder I made from an app, not possible?

EDIT: After realizing I have to make things public so to speak this is what I attempted to create a folder I could see when plugging the tablet in from my pc and copying stuff over there: File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) ; File theFile = new File(path+"/Portfolio/"); //if(!theFile.exists()) theFile.mkdir(); I comment...


Copying the android output

I wish to know one thing regarding android apk file and the output generated. Actually I want to take the output that comes after running an apk file, copy the output into another file and use it for some purpose. Friends tell me Can that be done ?






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top