Android -在扩展应用程序类时不能访问landroid/app/仪器。

时间:2022-09-02 12:35:15

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):

我正在慢慢地尝试学习android,但我遇到了一个无法解决的问题。我尝试用一些全局变量。我已经扩展了应用程序类。我添加了我认为是正确的清单(课程名称是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:

这就是我在我的算命活动中所拥有的。java文件:

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.

我基本上删除了所有的代码来尝试让这个类工作,以确保这个问题与其他问题无关。如果我删除了android::名字从我的清单,我不再得到错误。

Here is the exact error

这是准确的误差。

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

newInstance失败:Lcom / marctremblay /测试/ fortunecrunch / fortunecrunch;无法访问Landroid / app /仪器;

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

我难住了。就像我在很多例子中看到的一样。非常感谢您的意见!谢谢。

3 个解决方案

#1


1  

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

试着把这个算命的类放到它自己的文件中。java,这里面:

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

public class FortuneCrunch extends Application {
  @Override
  public void onCreate() {
    super.onCreate();
    // Initialize your variables here
  }
}

#2


3  

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

另外,要确保明确地让您的类公开,通过将公共类XYZ放到类中,而不是只使用类XYZ。

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

否则,该类将被视为包,这将导致相同的错误。

#3


0  

Every time you get the below error, change the name of your global variable class (FortuneCrunch) and do the next steps carefully again.

每次您获得以下错误时,请更改您的全局变量类的名称(FortuneCrunch),并再次小心地执行下一个步骤。

newInstance failed: ....

newInstance失败:....

#1


1  

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

试着把这个算命的类放到它自己的文件中。java,这里面:

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

public class FortuneCrunch extends Application {
  @Override
  public void onCreate() {
    super.onCreate();
    // Initialize your variables here
  }
}

#2


3  

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

另外,要确保明确地让您的类公开,通过将公共类XYZ放到类中,而不是只使用类XYZ。

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

否则,该类将被视为包,这将导致相同的错误。

#3


0  

Every time you get the below error, change the name of your global variable class (FortuneCrunch) and do the next steps carefully again.

每次您获得以下错误时,请更改您的全局变量类的名称(FortuneCrunch),并再次小心地执行下一个步骤。

newInstance failed: ....

newInstance失败:....