Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - not accessible to landroid/app/instrumentation when extending application class

Tags:

java

android

Im slowly trying to learn android but Ive run into a hang up that I can't quite figure out. I'm trying to work with some global variables. I have extended the Application class. I have added what I think is correct to the manifest (the name of the class is Fortune Crunch):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.marctremblay.test.fortunecrunch"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" android:debuggable="true"
        android:name=".FortuneCrunch">
        <activity
            android:name=".FortuneCrunchActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
    </activity>
</application>

Then this is what I have in my FortuneCrunchActivity.java file:

package com.marctremblay.test.fortunecrunch;
import android.app.Activity;
import android.app.Application;


import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

class FortuneCrunch extends Application{

FortuneCrunch()
{   
}


}


class FortuneCrunchActivity extends Activity {
    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {

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

    }

}

I have basically removed all my code to try and get this class working just to be sure the issue isnt with anything else. If I remove the android::name from my manifest I no longer get the error.

Here is the exact error

newInstance failed: Lcom/marctremblay/test/fortunecrunch/FortuneCrunch; not accessible to Landroid/app/Instrumentation;

I am stumped. I have this setup just as I have seen it in many examples. Ideas would be greatly appreciated! Thanks.

like image 310
user1179567 Avatar asked Jan 31 '12 05:01

user1179567


2 Answers

Also, make sure to explicitly make your class public by putting public class XYZ instead of just class XYZ.

Otherwise the class will be considered as package, which will result in the same error.

like image 150
Sabo Avatar answered Sep 16 '22 16:09

Sabo


Try putting the FortuneCrunch class in its own file, FortuneCrunch.java, with this inside:

package com.marctremblay.test.fortunecrunch;
import android.app.Application;

public class FortuneCrunch extends Application {
  @Override
  public void onCreate() {
    super.onCreate();
    // Initialize your variables here
  }
}
like image 30
chiuki Avatar answered Sep 17 '22 16:09

chiuki