SUP 2.2 + Android throw exception at Application.getInstance().setApplicationContext(this);

340 Views Asked by At

I try to use Sybase Unwired Platform with generated code for Android. I have exception in following code:

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);    

Application app = Application.getInstance();
        
String AppName = "timesheets";
        
if (app.getApplicationIdentifier() == null)
    app.setApplicationIdentifier(AppName);

if (app.getApplicationContext() == null)
    app.setApplicationContext(this); //Place where app crashes

Debug window look like this:

debug window

All crashes after beginning of execution of that line:

crash message box

Android version is 4.1.2 (API 16)

Why does it crash?

4

There are 4 best solutions below

1
On

I don't even know what Sybase is, but I don't believe setting application context to Activity is good idea. this refers to Activity, doesn't it?

Actually, I can't even find that method in Android API:

Application.setApplicationContext(this)

Looked here: Application and ContextWrapper and Context

What are you trying to archive by this line?

0
On

I corrected source to more clear form:

com.sybase.mobile.Application app = com.sybase.mobile.Application.getInstance();

String AppName = "timesheets";

if (app.getApplicationIdentifier() == null)
   app.setApplicationIdentifier(AppName);

if (app.getApplicationContext() == null)
   app.setApplicationContext(this);
1
On

try this:

 app.setApplicationContext(getApplicationContext());
0
On

What I used to do in Android & SUP 2.1 is Application.getInstance().setApplicationContext(getApplicationContext());

I see you are still passing the activity as context. Try to pass the application context like I wrote in my line above.