Reputation: 13290
Yes. I know this is trivial. But this is getting silly.
Image proving the error:
The code:
package apack.age;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
public class DisplayContactActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.display_contact_layout);
}
public void openSubreddit(View view)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.reddit.com")));
}
public void openTwitter(View view)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://twitter.com")));
}
public void openGmail(View view)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("www.gmail.com")));
}
}
Seriously. There's 5 open and 5 close braces. This is my first attempt at an android app but I have 3 years of Java experience so this is pretty frustrating.
Run errors out. Refresh does nothing. Project clean does nothing. Auto code format in eclipse (CTRL + SHIFT + F) does nothing.
EDIT 1: Copying the code to a new class gets it to compile. I'm running the new version of Eclipse: Juno. I've done source -> cleanup and it just says "nothing to change" every time!
Upvotes: 6
Views: 2558
Reputation: 178
I tried some of the solutions suggested here, no luck, then tried the below, seems good.
I moved the Java file out of the source tree. Of course, compile errors lit up everywhere else in the tree.
I created a new Java file for the class. I right-clicked on an error to generate the file. I set the parent class in the dialog.
I fixed the errors in the file - constructor required because of parent class - with temporary code.
With the old code open in a text editor (Notepad++), I chunk-by-chunk copy-pasted the old code in, fixing imports as required by right-clicking on the errors.
It compiles happily now.
Grumble. Flaky tools. Grumble.
Upvotes: 0
Reputation: 22070
Edit: Please upgrade to ADT 20.0.1, where this has been fixed.
Switch to the Lint view, use the Clean button to remove all lint errors. There is a bug with lint in ADT 20, that it sometimes takes over the Java compiler bugs.
You can verify if this is really the problem by looking at the "Origin" column of this bug in your Problems view. Normally that should be "Java problem" for this error, but it will be "Lint" instead.
Upvotes: 5
Reputation: 61
Here are some tips for Eclipse users who are experiencing this issue. Please try the following, which solved this problem for me (I was using this download of the IDE: eclipse-SDK-4.2-macosx-cocoa-x86_64.tar):
1) mv the offending source .java file to a new file. 2) Refresh eclipse (the project via right-clicking the project name). 3) mv the new file back to the original name. 4) Refresh eclipse again.
This solved the issue for me. It was nothing about the code, it happened for me, intermittently throughout my coding session, even in a very small file in which it was not easy to misplace any closing braces :-)
Upvotes: 0
Reputation: 9399
There's gotta be a snapin in your eclipse with the issue. Have you tried a virgin eclipse install?
Upvotes: 1
Reputation: 117597
Try to save the file with Ctrl+S
, it happens to me sometimes. Also, it seems that you forget to insert the package name at the beginning of the code:
package com.example.my_application;
Upvotes: 1