View Single Post
  #7   Spotlight this post!  
Unread 29-12-2010, 14:31
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: Native C string (char*) to java String

Ok, i've narrowed it down a bit, and the crashing is due to Double.parseDouble("") throwing an exception because GetString is always returning "" (empty string)
Code:
public String GetString(String name)
    {
        Pointer ptr = Pointer.createStringBuffer(name);
        int retturn = getstringfnc.call1(ptr);
        Address adr = Address.fromPrimitive(retturn);
        String str = Pointer.NativeUnsafeGetString(adr);
        System.out.println("String:'"+str+"'");
        ptr.free();
        return str;
    }
    public double GetDouble(String name)
    {
        try
        {
            return Double.parseDouble(GetString(name));
        }
        catch(Throwable t) { }
        return 0;
    }
and
Code:
public void operatorControl() {
getWatchdog().setEnabled(false);
    while (isOperatorControl()) {

        if (z.CanSend()) {
            z.Add("taco", stick.getY());
            z.Add("val", z.GetDouble("ival"));
            z.Send();
        }
        Timer.delay(0.01);
    }
    }
produces
Code:
String:''
String:''
String:''
String:''
String:''
String:''
String:''
String:''
String:''
String:''
String:''
String:''
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote