Android &引用;错误:找不到符号类应用程序“;
我有一个外部包类(我的自定义库),我想将其包含在项目中。它使用Android &引用;错误:找不到符号类应用程序“;,android,android-studio,Android,Android Studio,我有一个外部包类(我的自定义库),我想将其包含在项目中。它使用活动,但如您所见显示错误 如果我把这个命令放在主项目类中,它工作得很好。。。怎么办 代码如下: package com.__MyDefaultLibrary; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; import android
活动
,但如您所见显示错误
如果我把这个命令放在主项目类中,它工作得很好。。。怎么办
代码如下:
package com.__MyDefaultLibrary;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.ScaleAnimation;
import android.widget.*;
import java.io.File;
import java.util.Calendar;
//
import android.app.Activity;
import com.oceanesa.samplevideorecorder.R;
public class __MyDefaultFunctions{
public android.app.Activity actv1 = android.app.Activity;
public void Initt(){
PreferenceManager.setDefaultValues(actv1.getBaseContext(), R.xml.mypreferences, false);
}
// ========== MY CUSTOM LIBRARY =============//
//button find
public Button fvb(int id) {
return (Button) actv1.findViewById(id);
}
//message show
public void msg(String text) {
Toast.makeText(actv1.getApplicationContext(), text, Toast.LENGTH_LONG).show();
}
public View.OnClickListener optionsListener2 = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(actv1.getBaseContext(), com.__MyDefaultLibrary.__MyDefaultPreferencesInit1.class);
actv1.startActivity(i);
}
};
}
和AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.oceanesa.samplevideorecorder"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="false" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@style/AppTheme"
>
<activity
android:name="com.oceanesa.samplevideorecorder.VideoCaptureExample"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.__MyDefaultLibrary.__MyDefaultPreferencesInit1"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
只需将上下文传递给类即可更新答案
public class MyClass {
private static Context mContext;
private static Activity mActivity;
public MyClass(Context c) {
mContext= c;
}
public MyClass(Activity act) {
mActivity= act;
}
public static void showToastMethod() {
// then passing context or activity to
Toast.makeText(mContext, "mymessage ", Toast.LENGTH_SHORT).show();
// or Toast.makeText(mActivity, "mymessage ", Toast.LENGTH_SHORT).show();
}
}
最后,我在topic: 问题出在我的代码中。根本不需要调用
和id.app
。我没有将活动
传递到我的外部文件,在那里我无法调用任何东西
我必须通过这样的活动(从主项目文件):
需要一些修改 请和我分享你的一段经历code@MinaFawzy我已经在问题的底部添加了链接。您是如何创建包含此代码的Android Studio项目的?可能是重复的谢谢,但我无法理解<代码>活动属于
andoid.app
软件包的类别。我在我的图书馆,我没有任何活动课。。(此外,根本不像ActivityName
)。在我的主项目文件中,我有类XYZ扩展Activty
.p.s。在这两个文件中,它都成功地导入了yy,但在上面给出的示例文件中,它显示了未使用的导入语句
。因此,您在这一行中尝试执行的操作android.app.Activity actv1=android.app.Activity??首先,感谢您的回答。。。。。。。在这个外部文件(我们称它为MyFunctions.java
)中,我有以下代码:Toast.makeText(actv1.getApplicationContext(),“Helooo”,Toast.LENGTH_LONG).show()代码>并希望使其正常工作。。因此,我想设置actv1
,因为如果没有类名,getApplicationContext()
返回错误。只需将此代码actv1.getApplicationContext()替换为上下文,它将执行相同的任务
public MyExternalClass myEx = new MyExternalClass(Activity);