I am not that good to understand all the possibility of Java, especially if it's not my code.
So, http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/text/Html.java#Html.fromHtml%28java.lang.String%29 , is it all I need to modify Html.fromHtml() ?
But I don't understand how it's works : Is it a good way to create a new class like Html2 and copy/paste all the code ? When I do that I have some errors that I don't understand :
private static class HtmlParser {
private static final HTMLSchema schema = new HTMLSchema();
}
He tells my Htmlschema cannot be resolved to a type, and to add the class HtmlSchema... but where can i find it ?
And this :
return XmlUtils.convertValueToInt(color, -1);
XmlUtils cannot be resolved.
The rest of the errors have been solved with the help of Eclipse
He tells my Htmlschema cannot be resolved to a type, and to add the class HtmlSchema... but where can i find it ?
import org.ccil.cowan.tagsoup.HTMLSchema;
HTMLSchema is from TagSoup, a JAR used inside of Android's frameworks but not exposed through the Android SDK.
XmlUtils cannot be resolved.
import com.android.internal.util.XmlUtils;
XmlUtils is a class from the Android firmware, not exposed through the Android SDK.
Related
I'm new in java, please help me to understand this.
I can see there is ReadHtml class and defined with one public method. But when i put this code in ecplise, it shows red mark under WebClient with tag that "this cannot resolved to a type". May I know what does it mean? Gone through all about method definition but couldn't find any remedy to understand this.
Can I get any help ?
public class ReadHtml {
public static LinkedList<String> readJacksonCounty(String urlName, String pStartDate,String pFinishDate)
{
LinkedList<String> xmlListReturn=new LinkedList<String>();
System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "error");
final WebClient webClient1 = new WebClient(BrowserVersion.CHROME);
webClient1.setJavaScriptTimeout(60000);
webClient1.getCookieManager().setCookiesEnabled(true);//enable cookies
webClient1.getCache().clear();
You are missing an import of this library:
import com.gargoylesoftware.htmlunit.WebClient;
Add this to the top of your file (and read dsp_user's comment for future reference).
Basically "...cannot be resolved to a type" means that type is not available on the class path. If you're just using eclipse refere to How to import a jar in Eclipse.
If you already added the needed jar onto your class path, you are missing the import statement. Imports just make it so that you dont have to use a class's fully qualified name. (you can type
MyClass myClass;
as opposed to
com.some.package.MyClass myClass;
if you add
import com.some.package.MyClass;
at the top of your file.
Note that if you want to build a jar from your project you'll need some kind of build tool. If you choose to use Maven, which is very common, just read any tutorial on how to get started and manage dependencies.
I would like to reference a class Bag in a JAR file, but Eclipse is telling me that Bag cannot be resolved to a type. I have added the JAR in which Bag is defined to the classpath for the project, but the error is still there. What am I doing wrong?
I think you can't do that, because the Bag class in algs4.jar is inside the default package.
Before J2SE 1.4, we still can import classes from the default package using a syntax like this:
import Unfinished;
But from J2SE 1.5, that's no longer allowed. So if we want to access a default package class from within a packaged class requires moving the default package class into a package of its own. Read here for more detail explanation :
How to access java-classes in the default-package?
Some options you can choose :
Access the class via reflection or some other indirect method. But it is a little bit hard, something like this :
Class fooClass = Class.forName("FooBar");
Method fooMethod = fooClass.getMethod("fooMethod", new Class[] { String.class });
String fooReturned = fooMethod.invoke(fooClass.newInstance(), new String("I did it"));
If you own the source code of that jar library, you need to put it in properly package and wrap it again as a new jar library.
You may need to either fully qualify the Bag class, or import it.
I am using Play Framework 1.2.5, and trying to use DateTime from Joda Time instead of the usual java.util.Date. I am trying to implement a format method for use in my views.
The Play documentation says I can create my own custom java extensions for use in templates, but it doesn't seem to be working for me. I have followed the example in the docs to no avail.
My custom extension:
package ext;
import org.joda.time.DateTime;
import play.templates.JavaExtensions;
public class DateTimeExtensions extends JavaExtensions {
public static String format(DateTime datetime, String format) {
return datetime==null ? "" : datetime.toString(format);
}
}
My template code:
${subProject?.startDate?.format('yyyy-MM-dd')}
And the error I am receiving:
Exception raised was MissingMethodException : No signature of method: org.joda.time.DateTime.format() is applicable for argument types: (java.lang.String) values: [yyyy-MM-dd]
It looks like Play isn't detecting my custom extension as the documentation says it should. Does anyone have any suggestions on how to make this work?
Your extension class looks good to me. The documentation states that you have to restart your application for the extension to become active. If that doesn't work, try running play clean. Doing so deletes temporary files, including cached bytecode, which will hopefully resolve your issue.
Im trying to use Scala and Java in one project. Im working with the Scla IDE for Eclipse. I have two packages in my Scala Project: one for my scala code and one for my java code.
Now lets say I create new JavaClass with one static member.
package javastuff;
public class MyJavaClass {
public static String MESSAGE = "Im Java";
}
After that Im trying to get access to this variale and somehow I cannot. Funny thing, because scala is able to see the Java class "MyJavaClass" just not able to see MESSAGE.
import javastuff.MyJavaClass
object Main {
def main(args: Array[String]) {
println(MyJavaClass.MESSAGE)
}
}
Value MESSAGE is not a member of object javastuff.MyJavaClass
If I use Project/Clean... 1-2x times eclipse is maybe starting realizing that the member MESSAGE is really there and everything is fine. Is this normal? Maybe Im doing something wrong, I know eclipse is really a bad IDE and I should maybe try IntelliJ, but somehow I like eclipse and I would like to use later some of my favorite plugins, thats why I would not change the IDE just because of this problem. Any ideas how to handle this problem better?
Scala doesn't have any static fields. Here is a blogpost about it
btw. public static without final is pretty bad design (no encapsulation => possible memory leaks)
By running System.loadLibrary("myAPI"), I verified that the DLL file "myAPI.dll" can be successfully loaded into my Eclipse Java project. Now I need to call methods specified inside this DLL file from my Java code. To do this, I added JNA to my Java project. Then I wrote the below-given code snippet that should be able to get instances of classes IProject and ProjectFactory (specified in the DLL file).
I still don't understand how to properly implement this with JNA. I checked different threads, e.g. this one, but the ones I checked don't provide an answer. Any help is highly appreciated. Thanks.
import com.sun.jna.Library;
import com.sun.jna.Native;
public class MyClass {
public interface myAPI extends Library {
//...
}
void LoadProj() {
myAPI api = (myAPI) Native.loadLibrary("myAPI",myAPI.class);
String fileName = "xxx.sp";
IProject project; // this is wrong but shows what I am trying to do
try {
project = ProjectFactory.LoadProject(fileName);
}
catch (Exception ex) {
MessageBox.Show(this, ex.Message, "Load failure");
}
}
}
Not sure what problem you are facing but as a practice your myAPI interface should declare all the methods verbatim with appropriate parameter mapping. I don't see any methods inside your interface.
Please checkout the this link as well as the link mentioned above by #Perception
If there are no Java classes or Java source hidden inside this DLL (which would be ... strange), then it will never work this way. You can't instantiate C# classes or use C# interfaces. MessageBox.Show( isn't Java either, it is Windows Forms code.