Eclipse does not recognize some coda-parts
Sorry for the unspecific title, but I do not know how to formulate it.
I have the following problem:
I Have installed Android SDK on my laptop and on another PC. I have to work on both PC. When transport a Project form my Laptop, I sometimes get the problem, that on the PC, parts of the code get the XXX cannot be resolved to a type.
Example: The Code is not so interesting, the problem is in the line, "AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);"
package com.example.alertdialog;
import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
public class AlertDialog extends Activity {
/** Called when the activity is first created. */
public static final int DIALOG_DELETE_YES_NO_MESSAGE = 1;
public static final int DIALOG_DELETE_ALL_MESSAGE = 2;
public class ExampleApp extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
alt_bld.setMessage("Do you want to close this window ?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(Di开发者_运维百科alogInterface dialog, int id) {
// Action for 'NO' Button
dialog.cancel();
}
});
AlertDialog alert = alt_bld.create();
// Title for AlertDialog
alert.setTitle("Title");
// Icon for AlertDialog
alert.setIcon(R.drawable.icon);
alert.show();
}
}
}
In another case, extend a class from a BaseAdapter. On the Laptop, I can overwrite functions like "getVIew", on the PC, there is an Error if I use "@Override".
This is the error I get: "Multiple markers at this line - implements android.widget.Adapter.getView - The method getView(int, View, ViewGroup) of type ImageAdapter must override a superclass method"
Any ideas as to what the problem is?
This happened to me too. I found this link: http://androidideasblog.blogspot.com/2010/08/re-import-android-project-issue.html
Basically, as he explains:
Eclipse is defaulting to Java 1.5 and you have classes implementing interface methods (which in Java 1.6 can be annotated with @Override, but in Java 1.5 can only be applied to methods overriding a superclass method).
Go to your project/ide preferences and set the java compiler level to 1.6 and also make sure you select JRE 1.6 to execute your program from eclipse.
It might be a problem with the android build target. Right click the project (in the left Package explorer in Eclipse) and choose Properties, tab Android and check that a Android SDK is selected. Click Apply.
精彩评论