我有一个编译问题。我遵循了关于Android的"Hello world"程序的教程,我已经成功地编译和运行了几次程序。但是第二天,当我打开电脑时,我试图再次运行该程序,它给了我以下错误:
"C:Documents and Settingssh0neMy DocumentsNetBeansProjectsHelloAndroidbuild.xml:83: The following error occurred while executing this line:
C:Program FilesAndroidandroid-sdktoolsantbuild.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 FilesAndroidandroid-sdktoolslibanttasks.jar]".
当我搜索互联网(也StackOverflow.com),所有我发现的是关于"taskdef类com.android.ant.SetupTask找不到"问题的讨论,但这并没有帮助,因为我没有那个错误。我检查了我的路径(本地)。属性,build.xml, android SDK路径),一切似乎都很好(昨天一切都像一个魅力,从那以后我没有触摸/改变任何东西,现在我不能构建/运行应用程序)。我试过"清洁和构建",它给了我同样的错误。
我使用Netbeans 7.0.1与nandroid插件(7.0+)。我安装了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 FilesJavajdk1.7.0jre
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 Settingssh0neMy DocumentsNetBeansProjectsHelloAndroidbuild.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 FilesNetBeans 7.0.1javaant
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 Settingssh0neMy DocumentsNetBeansProjectsHelloAndroidbuild.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 Settingssh0neMy DocumentsNetBeansProjectsHelloAndroidbuild.xml
Setting ro project property: ant.file.type.HelloAndroid -> file
Project base dir set to: C:Documents and Settingssh0neMy DocumentsNetBeansProjectsHelloAndroid
+Target:
Adding reference: ant.LocalProperties
Setting project property: sdk.dir -> C:Program FilesAndroidandroid-sdk
Loading C:Documents and Settingssh0neMy DocumentsNetBeansProjectsHelloAndroidant.properties
Setting project property: target -> android-8
Importing file C:Program FilesAndroidandroid-sdktoolsantbuild.xml from C:Documents and Settingssh0neMy DocumentsNetBeansProjectsHelloAndroidbuild.xml
Overriding previous definition of reference to ant.projectHelper
Adding reference: ant.projectHelper
parsing buildfile C:Program FilesAndroidandroid-sdktoolsantbuild.xml with URI = file:/C:/Program%20Files/Android/android-sdk/tools/ant/build.xml
Setting ro project property: ant.file. -> C:Program FilesAndroidandroid-sdktoolsantbuild.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 FilesAndroidandroid-sdktoolslibanttasks.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 Settingssh0neMy DocumentsNetBeansProjectsHelloAndroidbuild.xml:83: The following error occurred while executing this line:
C:Program FilesAndroidandroid-sdktoolsantbuild.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 FilesAndroidandroid-sdktoolslibanttasks.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 FilesAndroidandroid-sdktoolsantbuild.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 FilesAndroidandroid-sdktoolslibanttasks.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:对不起,我的英语不好,这不是我的母语。
检查日志文件清楚地显示类com.android.sdklib.ISdkLog不在Ant的类路径中。这导致没有找到类com.android.ant.NewSetupTask的问题。
似乎android SDK没有安装在您的机器上,或者至少用于构建android项目的ant任务不在ant的类路径中。我认为第二种选择更相关。在这种情况下,您应该找到合适的jar文件并将其添加到ant/lib
。