我有一个编译问题。我遵循了有关 Android 的“Hello world”程序的教程,并且成功地编译和运行了该程序几次。但是第二天打开电脑,我再次尝试运行程序,它给了我以下错误:
"C:\Documents and Settings\sh0ne\My Documents\NetBeansProjects\HelloAndroid\build.xml:83: The following error occurred while executing this line:
C:\Program Files\Android\android-sdk\tools\ant\build.xml:65: taskdef A class needed by class com.android.ant.NewSetupTask cannot be found: com/android/sdklib/ISdkLog using the classloader AntClassLoader[C:\Program Files\Android\android-sdk\tools\lib\anttasks.jar]".
当我搜索互联网(以及 StackOverflow.com)时,我发现的只是关于“找不到任务定义类 com.android.ant.SetupTask”问题的讨论,但这无济于事,因为我没有那个错误。我检查了我的路径(local.properties、build.xml、Andoid SDK 的路径),一切似乎都很好(昨天一切都像一个魅力,从那时起我没有触摸/更改任何东西,现在我无法构建/运行应用程序)。我尝试了“清理和构建”,它给了我同样的错误。
我正在使用带有 nbandroid 插件(7.0+)的 Netbeans 7.0.1。我安装了 Android 4 (API 14) 和 Android 2.2 (API 8)。它给了我同样的错误。我正在运行 Windows XP SP3。
源代码:
package org.brokenbyte.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android!");
setContentView(tv);
}
}
这是完整的调试输出:
Adding reference: ant.PropertyHelper
Detected Java version: 1.7 in: C:\Program Files\Java\jdk1.7.0\jre
Detected OS: Windows XP
Adding reference: ant.ComponentHelper
Trying to override old definition of task java
+Datatype java org.apache.tools.ant.module.bridge.impl.ForkedJavaOverride
parsing buildfile jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-ant-browsetask.jar!/org/netbeans/modules/ant/browsetask/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-ant-browsetask.jar!/org/netbeans/modules/ant/browsetask/antlib.xml from a zip file
parsing buildfile jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
+Datatype nbbrowse org.netbeans.modules.ant.browsetask.NbBrowse
parsing buildfile jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-ant-browsetask.jar!/org/netbeans/modules/ant/browsetask/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-ant-browsetask.jar!/org/netbeans/modules/ant/browsetask/antlib.xml from a zip file
+Datatype antlib:org.netbeans.modules.ant.browsetask:nbbrowse org.netbeans.modules.ant.browsetask.NbBrowse
parsing buildfile jar:file:/C:/Program%20Files/NetBeans%207.0.1/profiler/ant/nblib/org-netbeans-modules-profiler.jar!/org/netbeans/modules/profiler/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans%207.0.1/profiler/ant/nblib/org-netbeans-modules-profiler.jar!/org/netbeans/modules/profiler/antlib.xml from a zip file
+Datatype nbprofileattach org.netbeans.modules.profiler.ant.NBProfileAttachTask
+Datatype nbprofiledirect org.netbeans.modules.profiler.ant.NBProfileDirectTask
parsing buildfile jar:file:/C:/Program%20Files/NetBeans%207.0.1/profiler/ant/nblib/org-netbeans-modules-profiler.jar!/org/netbeans/modules/profiler/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans%207.0.1/profiler/ant/nblib/org-netbeans-modules-profiler.jar!/org/netbeans/modules/profiler/antlib.xml from a zip file
+Datatype antlib:org.netbeans.modules.profiler:nbprofileattach org.netbeans.modules.profiler.ant.NBProfileAttachTask
+Datatype antlib:org.netbeans.modules.profiler:nbprofiledirect org.netbeans.modules.profiler.ant.NBProfileDirectTask
parsing buildfile jar:file:/C:/Program%20Files/NetBeans%207.0.1/apisupport/ant/nblib/org-netbeans-modules-apisupport-ant.jar!/org/netbeans/modules/apisupport/ant/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans%207.0.1/apisupport/ant/nblib/org-netbeans-modules-apisupport-ant.jar!/org/netbeans/modules/apisupport/ant/antlib.xml from a zip file
+Datatype nbinstaller org.netbeans.modules.apisupport.ant.InstallModuleTask
parsing buildfile jar:file:/C:/Program%20Files/NetBeans%207.0.1/apisupport/ant/nblib/org-netbeans-modules-apisupport-ant.jar!/org/netbeans/modules/apisupport/ant/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans%207.0.1/apisupport/ant/nblib/org-netbeans-modules-apisupport-ant.jar!/org/netbeans/modules/apisupport/ant/antlib.xml from a zip file
+Datatype antlib:org.netbeans.modules.apisupport.ant:nbinstaller org.netbeans.modules.apisupport.ant.InstallModuleTask
parsing buildfile jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-debugger-jpda-ant.jar!/org/netbeans/modules/debugger/jpda/ant/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-debugger-jpda-ant.jar!/org/netbeans/modules/debugger/jpda/ant/antlib.xml from a zip file
+Datatype nbjpdaconnect org.netbeans.modules.debugger.jpda.ant.JPDAConnect
+Datatype nbjpdastart org.netbeans.modules.debugger.jpda.ant.JPDAStart
+Datatype sourcepath org.netbeans.modules.debugger.jpda.ant.JPDAStart$Sourcepath
+Datatype nbjpdareload org.netbeans.modules.debugger.jpda.ant.JPDAReload
+Datatype nbjpdaappreloaded org.netbeans.modules.debugger.jpda.ant.JPDAAppReloaded
parsing buildfile jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-debugger-jpda-ant.jar!/org/netbeans/modules/debugger/jpda/ant/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-debugger-jpda-ant.jar!/org/netbeans/modules/debugger/jpda/ant/antlib.xml from a zip file
+Datatype antlib:org.netbeans.modules.debugger.jpda.ant:nbjpdaconnect org.netbeans.modules.debugger.jpda.ant.JPDAConnect
+Datatype antlib:org.netbeans.modules.debugger.jpda.ant:nbjpdastart org.netbeans.modules.debugger.jpda.ant.JPDAStart
+Datatype antlib:org.netbeans.modules.debugger.jpda.ant:sourcepath org.netbeans.modules.debugger.jpda.ant.JPDAStart$Sourcepath
+Datatype antlib:org.netbeans.modules.debugger.jpda.ant:nbjpdareload org.netbeans.modules.debugger.jpda.ant.JPDAReload
+Datatype antlib:org.netbeans.modules.debugger.jpda.ant:nbjpdaappreloaded org.netbeans.modules.debugger.jpda.ant.JPDAAppReloaded
parsing buildfile jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-javawebstart.jar!/org/netbeans/modules/javawebstart/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-javawebstart.jar!/org/netbeans/modules/javawebstart/antlib.xml from a zip file
+Datatype jnlpsignjars org.netbeans.modules.javawebstart.SignJarsTask
parsing buildfile jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-javawebstart.jar!/org/netbeans/modules/javawebstart/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-javawebstart.jar!/org/netbeans/modules/javawebstart/antlib.xml from a zip file
+Datatype antlib:org.netbeans.modules.javawebstart:jnlpsignjars org.netbeans.modules.javawebstart.SignJarsTask
parsing buildfile jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-java-source-ant.jar!/org/netbeans/modules/java/source/ant/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-java-source-ant.jar!/org/netbeans/modules/java/source/ant/antlib.xml from a zip file
Trying to override old definition of task javac
+Datatype javac org.netbeans.modules.java.source.ant.JavacTask
+Datatype translate-classpath org.netbeans.modules.java.source.ant.TranslateClassPath
parsing buildfile jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-java-source-ant.jar!/org/netbeans/modules/java/source/ant/antlib.xml with URI = jar:file:/C:/Program%20Files/NetBeans%207.0.1/java/ant/nblib/org-netbeans-modules-java-source-ant.jar!/org/netbeans/modules/java/source/ant/antlib.xml from a zip file
+Datatype antlib:org.netbeans.modules.java.source.ant:javac org.netbeans.modules.java.source.ant.JavacTask
+Datatype antlib:org.netbeans.modules.java.source.ant:translate-classpath org.netbeans.modules.java.source.ant.TranslateClassPath
Setting ro project property: ant.file -> C:\Documents and Settings\sh0ne\My Documents\NetBeansProjects\HelloAndroid\build.xml
Setting ro project property: ant.version -> Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Setting ro project property: ant.home -> C:\Program Files\NetBeans 7.0.1\java\ant
Setting project property: ant.junit.enabletestlistenerevents -> true
Setting ro project property: build.compiler.emacs -> true
Adding reference: ant.projectHelper
Adding reference: ant.parsing.context
Adding reference: ant.targets
parsing buildfile C:\Documents and Settings\sh0ne\My Documents\NetBeansProjects\HelloAndroid\build.xml with URI = file:/C:/Documents%20and%20Settings/sh0ne/My%20Documents/NetBeansProjects/HelloAndroid/build.xml
Setting ro project property: ant.project.name -> HelloAndroid
Adding reference: HelloAndroid
Setting ro project property: ant.project.default-target -> help
Setting ro project property: ant.file.HelloAndroid -> C:\Documents and Settings\sh0ne\My Documents\NetBeansProjects\HelloAndroid\build.xml
Setting ro project property: ant.file.type.HelloAndroid -> file
Project base dir set to: C:\Documents and Settings\sh0ne\My Documents\NetBeansProjects\HelloAndroid
+Target:
Adding reference: ant.LocalProperties
Setting project property: sdk.dir -> C:\Program Files\Android\android-sdk
Loading C:\Documents and Settings\sh0ne\My Documents\NetBeansProjects\HelloAndroid\ant.properties
Setting project property: target -> android-8
Importing file C:\Program Files\Android\android-sdk\tools\ant\build.xml from C:\Documents and Settings\sh0ne\My Documents\NetBeansProjects\HelloAndroid\build.xml
Overriding previous definition of reference to ant.projectHelper
Adding reference: ant.projectHelper
parsing buildfile C:\Program Files\Android\android-sdk\tools\ant\build.xml with URI = file:/C:/Program%20Files/Android/android-sdk/tools/ant/build.xml
Setting ro project property: ant.file. -> C:\Program Files\Android\android-sdk\tools\ant\build.xml
Setting ro project property: ant.file.type. -> file
+Target: all
+Target: clean
+Target: -setup
+Target: -build-setup
+Target: -pre-build
+Target: -code-gen
+Target: -pre-compile
+Target: -compile
+Target: -post-compile
+Target: -obfuscate
+Target: -dex
+Target: -crunch
+Target: -package-resources
+Target: -package
+Target: -set-mode-check
+Target: -set-debug-files
+Target: -set-debug-mode
+Target: -debug-obfuscation-check
+Target: -do-debug
+Target: debug
+Target: -release-prompt-for-password
+Target: -release-nosign
+Target: -release-obfuscation-check
+Target: -set-release-mode
+Target: release
+Target: -set-instrumented-mode
+Target: instrument
+Target: emma
+Target: -test-project-check
+Target: test
+Target: install
+Target: installd
+Target: installr
+Target: installi
+Target: installt
+Target: uninstall
+Target: help
Setting project property: adb.device.arg ->
Setting project property: android.package.excludes ->
Setting project property: version.code ->
Setting project property: version.name ->
Setting project property: aapt.resource.filter ->
Setting project property: java.encoding -> UTF-8
Setting project property: java.target -> 1.5
Setting project property: java.source -> 1.5
Setting project property: verbose -> false
Adding reference: android.antlibs
Finding class com.android.ant.NewSetupTask
Loaded from C:\Program Files\Android\android-sdk\tools\lib\anttasks.jar com/android/ant/NewSetupTask.class
Class org.apache.tools.ant.Task loaded from parent loader (parentFirst)
Class com.android.ant.NewSetupTask loaded from ant loader (parentFirst)
Class java.lang.Object loaded from parent loader (parentFirst)
Class java.lang.Throwable loaded from parent loader (parentFirst)
Class org.apache.tools.ant.BuildException loaded from parent loader (parentFirst)
Finding class com.android.sdklib.ISdkLog
C:\Documents and Settings\sh0ne\My Documents\NetBeansProjects\HelloAndroid\build.xml:83: The following error occurred while executing this line:
C:\Program Files\Android\android-sdk\tools\ant\build.xml:65: taskdef A class needed by class com.android.ant.NewSetupTask cannot be found: com/android/sdklib/ISdkLog using the classloader AntClassLoader[C:\Program Files\Android\android-sdk\tools\lib\anttasks.jar]
at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:551)
at org.apache.tools.ant.taskdefs.ImportTask.importResource(ImportTask.java:234)
at org.apache.tools.ant.taskdefs.ImportTask.execute(ImportTask.java:163)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor58.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:180)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:230)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:539)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
Caused by: C:\Program Files\Android\android-sdk\tools\ant\build.xml:65: taskdef A class needed by class com.android.ant.NewSetupTask cannot be found: com/android/sdklib/ISdkLog using the classloader AntClassLoader[C:\Program Files\Android\android-sdk\tools\lib\anttasks.jar]
at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:627)
at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:239)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor58.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:169)
at org.apache.tools.ant.taskdefs.ImportTask.importResource(ImportTask.java:225)
... 12 more
Caused by: java.lang.NoClassDefFoundError: com/android/sdklib/ISdkLog
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:594)
... 22 more
Caused by: java.lang.ClassNotFoundException: com.android.sdklib.ISdkLog
at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1361)
at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1311)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1064)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 25 more
我不明白发生了什么。请帮忙。
PS:对不起我的英语不好,这不是我的母语。