在为Android构建/编译“Hello World”时出错

时间:2011-11-13 11:23:43

标签: java android netbeans compiler-errors windows-xp-sp3

我有编译问题。我跟着关于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)时,我发现的所有内容都是关于“taskdef class 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:抱歉我的英语不好,不是我的母语。

1 个答案:

答案 0 :(得分:1)

检查您的日志文件清楚地显示类com.android.sdklib.ISdkLog不在Ant的类路径中。这会导致找不到类com.android.ant.NewSetupTask的问题。

似乎你的机器上没有安装android SDK,或者至少用于构建android项目的ant任务不在Ant的类路径中。我认为第二种选择更具相关性。在这种情况下,您应该找到合适的jar文件并将其添加到ant/lib