简体   繁体   中英

Netbeans doesn't see classes from referenced library

I'm using netbeans 7.2 with NBAndroid extension. In my android project, I'm referencing a library (ActionBarSherlock) that is not in jar (can't be, for some reason). The problem is, that netbeans doesn't see classes from that library and gives me errors (package does not exist etc.) However it builds and runs OK, the library is added correctly. Netbeans just doesn't see it.

Here is a screenshot .

Here is similar question, no solution package com.actionbarsherlock.app does not exist

Is there a way to fix this? Thanks for help!


EDIT: So I found a way to solve this, it's more a workaround than a solution. I created a jar file from the library classes called classes.jar. I put it in the libs folder, so netbeans sees it. Than I created custom_rules.xml (it's imported via build.xml). In it I move classes.jar away from the libs folder, so I can build it, and in the end I move it back.

<?xml version="1.0" encoding="UTF-8"?>
<project name="imported">

    <copy file="libs/classes.jar" todir="./" />
    <delete file="libs/classes.jar" />

    <target name="-post-compile">
        <copy file="./classes.jar" todir="libs/" />
        <delete file="./classes.jar" />
    </target>

</project>

The errors you see are because NetBeans doesn't recognize the packages, classes, methods, etc. When you build or run the program, NetBeans resorts to the Android project's Ant script, which apparently is configured correctly to find the classes. As far as compiling and running, you won't have a problem. However, if you want to use NetBeans' autocomplete and error-detection features, you need to configure it to detect your libs. To do this, just right click on your project name in the Project pane and click Properties from the context menu. Next, click on Libraries under Categories on the left. Then click Add JAR/Folder and navigate to the folder with your third-party library. You can select one of the options for the path then click OK. Now NetBeans should be able to find the identifiers and help you write your code.

Rather than doing some tricks in your build script I'd recommend you to use ActionBarSherlock as a library project. You should be able to do this in project customizer (select project, right click, choose properties).

Also see 'Including in YOur Project' bullet 2. in http://actionbarsherlock.com/usage.html

-Radim

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM