I have a MainActivity class
where I have implemented a main function. This main function calls a non-activity class by passing a context (unable to implement). In the non activity class, I want to access a file from the assets folder (which requires a context, hence the passing of one) and print it in the LogCat. This is how I am trying to do it
MainActivity:
public class MainActivity extends AppCompatActivity
{
public static void main(String[] args)
{
DiseaseAlgo(this).Parser();//Error. Unable to pass context
return;
}
//etc
}
NonActivity Class:
package com.iotaconcepts.aurum;
import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
import java.io.FileReader;
import java.io.IOException;
public class DiseaseAlgo
{
static Context mContext;
public DiseaseAlgo(Context context)
{
mContext = context;
}
public static void Parser() throws IOException
{
AssetManager as=mContext.getAssets();
String parse=as.open("symp.txt").toString();
String[] xx=parse.split("\t");
for(String i:xx)
Log.w("DiseaseAlgo", i);
}
}
I'm unable to figure out how to pass the context and call the 'DiseaseAlgo' method from this function. I keep getting:
package name.MainActivity.this cannot be referenced from static content
I need this to check the correctness of my text parsing and this is the only way to show it on the LogCat.