I just found out about dot42, a C# way to develop native Android Apps.
So my first project way to use some old code for generating CRC8 bytes. I created a new class in the project, copied the code over and tried to use it as normal.
I keep on getting java.lang.VerifyError
??
My class is simple mathematical computation. When I break it out into the main activity as a Public Method it works as expected.
But if I try to use the static class I get that error and I have no idea how to track down what the problem is? I tried adding the various android namespaces, tried making it a normal class to instantiate and even changed it to internal
The method CRC8.Compute("mystring")
does not even go into the compute code (if i put a break point there) It just throws and error right there on the method in MainActivity.cs
What do I have to do to use classes like this using dot42? (I looked at various examples on the site and I cannot pin point anything specific that needs to be done)
namespace dot42Application1
{
public class CRC8
{
static byte[] table = new byte[256];
// x8 + x2 + x + 1
const byte poly = 0x07;
public static string Compute(string ASCI)
{
int crcByte = Convert.ToInt16(ComputeChecksum(System.Text.Encoding.ASCII.GetBytes(ASCI)).ToString());
return crcByte.ToString("000");
}
public static byte ComputeChecksum(byte[] bytes)
{
byte CRCInitialValue = 0xFF;
//Final XOR value 0x00;
//Not revered bytes
//Not reverse CRC berfore final byte
if (bytes != null && bytes.Length > 0)
{
foreach (byte b in bytes)
{
CRCInitialValue = table[CRCInitialValue ^ b];
}
}
return CRCInitialValue;
}
public CRC8()
{
for (int i = 0; i < 256; ++i)
{
int temp = i;
for (int j = 0; j < 8; ++j)
{
if ((temp & 0x80) != 0)
{
temp = (temp << 1) ^ poly;
}
else
{
temp <<= 1;
}
}
table[i] = (byte)temp;
}
}
}
}
Maybe this helps. The stack trace shows...
Check some possible issues:
I have VS2010 and the newest dot42 plugin installed on Win7 OS, and tried to simulate your class expecting to see the same errors, however everything compiled good. The simulated static class is put in another file, in the same namespace. I call its static methods from another class elsewhere - MainActivity class.
Here is the simulated class:
using System;
using Android.App;
using Android.Os;
using Android.Widget;
using Dot42;
//using Dot42.Manifest;
namespace MyNamespace
{
public class CRC8
{
static byte[] table = new byte[256];
//x8 + x2 + x + 1
const byte poly = 0x07;
public static byte getCRC(byte[] _bytes)
{ return _bytes[0];
}
public static byte getCRC(String str_bytes)
{ return (byte) str_bytes.CharAt(0);
}
static CRC8()
{
//nothing happens so far
}
}
}
Here is the call within MainActivity class:
protected override void OnCreate(Bundle savedInstance)
{
base.OnCreate(savedInstance);
SetContentView(R.Layouts.MainLayout);
TextView text_view = (TextView)FindViewById(R.Ids.textView1);
byte[] aa = { 125, 54, 67, 78, 89 };
byte b_ret = 0;
b_ret = CRC8.getCRC("Ala ma kota");
text_view.Text += "CRC8.getCRC(String): " + b_ret.ToString() + "\n";
b_ret = CRC8.getCRC(aa);
text_view.Text += "CRC8.getCRC(byte[]): " + b_ret.ToString() + "\n";
text_view.Text += "CRC8.getCRC(ASCII.GetBytes): ";
text_view.Text += CRC8.getCRC(System.Text.Encoding.ASCII.GetBytes("ABC123XYZ")).ToString() + "\n";
}
Here is the output (API 18 i.e. Android 4.3):
Can you find any difference between our codes and so on? I hope this helps.