Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 错误:无法实例化活动组件信息_Java_Android_Runtimeexception_Instantiationexception - Fatal编程技术网

Java 错误:无法实例化活动组件信息

Java 错误:无法实例化活动组件信息,java,android,runtimeexception,instantiationexception,Java,Android,Runtimeexception,Instantiationexception,我在运行我的应用程序时遇到此错误: 12-14 12:04:42.088: E/AndroidRuntime(331): FATAL EXCEPTION: main 12-14 12:04:42.088: E/AndroidRuntime(331): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.awesomefilebuilderwidget/com.example.aw

我在运行我的应用程序时遇到此错误:

12-14 12:04:42.088: E/AndroidRuntime(331): FATAL EXCEPTION: main
12-14 12:04:42.088: E/AndroidRuntime(331): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.awesomefilebuilderwidget/com.example.awesomefilebuilderwidget.GridViewAdapter}: java.lang.InstantiationException: com.example.awesomefilebuilderwidget.GridViewAdapter
12-14 12:04:42.088: E/AndroidRuntime(331):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1746)
12-14 12:04:42.088: E/AndroidRuntime(331):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1854)
12-14 12:04:42.088: E/AndroidRuntime(331):  at android.app.ActivityThread.access$1500(ActivityThread.java:135)
12-14 12:04:42.088: E/AndroidRuntime(331):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1041)
12-14 12:04:42.088: E/AndroidRuntime(331):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-14 12:04:42.088: E/AndroidRuntime(331):  at android.os.Looper.loop(Looper.java:150)
12-14 12:04:42.088: E/AndroidRuntime(331):  at android.app.ActivityThread.main(ActivityThread.java:4333)
12-14 12:04:42.088: E/AndroidRuntime(331):  at java.lang.reflect.Method.invokeNative(Native Method)
12-14 12:04:42.088: E/AndroidRuntime(331):  at java.lang.reflect.Method.invoke(Method.java:507)
12-14 12:04:42.088: E/AndroidRuntime(331):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-14 12:04:42.088: E/AndroidRuntime(331):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-14 12:04:42.088: E/AndroidRuntime(331):  at dalvik.system.NativeStart.main(Native Method)
12-14 12:04:42.088: E/AndroidRuntime(331): Caused by: java.lang.InstantiationException: com.example.awesomefilebuilderwidget.GridViewAdapter
12-14 12:04:42.088: E/AndroidRuntime(331):  at java.lang.Class.newInstanceImpl(Native Method)
12-14 12:04:42.088: E/AndroidRuntime(331):  at java.lang.Class.newInstance(Class.java:1409)
12-14 12:04:42.088: E/AndroidRuntime(331):  at android.app.Instrumentation.newActivity(Instrumentation.java:1040)
12-14 12:04:42.088: E/AndroidRuntime(331):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1738)
12-14 12:04:42.088: E/AndroidRuntime(331):  ... 11 more
以下是我的GridViewAdapter类:

package com.example.awesomefilebuilderwidget;

IMPORTS

public class GridViewAdapter extends BaseAdapter {
private Context Context;

// Keep all Images in array list
public ArrayList<Integer> drawables = new ArrayList<Integer>();

CheckBox mCheckBox=null;

// Constructor
public GridViewAdapter(Context c){
    Context = c;
    Log.d("GridViewAdapter", "Constructor is set");

    drawables.add(R.drawable.pattern1);
    Log.d("GridViewAdapter", "pattern1 added");

    drawables.add(R.drawable.pattern2);
    Log.d("GridViewAdapter", "pattern2 added");

    drawables.add(R.drawable.trashcan);
    Log.d("GridViewAdapter", "trashcan added");

    drawables.add(R.drawable.ic_launcher);
    Log.d("GridViewAdapter", "ic_launcher added");
}

public void setCheckBox(CheckBox checkbox){
    mCheckBox=checkbox;
}

@Override
// How many items are in the data set represented by this Adapter
public int getCount() {
    return drawables.size();
}

@Override
// Get the data item associated with the specified position in the
// data set
public Object getItem(int position) {
    return drawables.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

public boolean isSdReadable() {

    boolean mExternalStorageAvailable = false;
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
    // We can read and write the media
    mExternalStorageAvailable = true;
    Log.i("isSdReadable", "External storage card is readable.");
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
    // We can only read the media
    Log.i("isSdReadable", "External storage card is readable.");
    mExternalStorageAvailable = true;
    } else {
    // Something else is wrong. It may be one of many other
    // states, but all we need to know is we can neither read nor write
    mExternalStorageAvailable = false;
    }

    return mExternalStorageAvailable;
    }

public Bitmap getThumbnail() {

    final String APP_PATH_SD_CARD = "/TEST/";
    final String APP_THUMBNAIL_PATH_SD_CARD = "thumbnails";
    String filename = "AFBWIcon.png";

    String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath() + APP_PATH_SD_CARD + APP_THUMBNAIL_PATH_SD_CARD;
    Bitmap thumbnail = null;

    // Look for the file on the external storage
    try {
    if (isSdReadable() == true) {
    thumbnail = BitmapFactory.decodeFile(fullPath + "/" + filename);
    }
    } catch (Exception e) {
    Log.e("getThumbnail() on external storage", e.getMessage());
    }

    // If no file on external storage, look in internal storage
    if (thumbnail == null) {
    try {
    File filePath = Context.getFileStreamPath(filename);
    FileInputStream fi = new FileInputStream(filePath);
    thumbnail = BitmapFactory.decodeStream(fi);
    } catch (Exception ex) {
    Log.e("getThumbnail() on internal storage", ex.getMessage());
    }
    }
    return thumbnail;
    }



@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Try to reuse the views
    ImageView view = (ImageView) convertView;
    @SuppressWarnings("unused")
    boolean checked = (mCheckBox==null)?false:(((CheckBox)  mCheckBox).isChecked());
    // if convert view is null then create a new instance else reuse it
    if (view == null) {
        view = new ImageView(Context);
        Log.d("GridViewAdapter", "new imageView added");
    }
    if(checked = true){
        isSdReadable();
        try {
            FileInputStream in = Context.openFileInput("BitmapImage");
            // Load back the image file to confirm it works
            Bitmap bitmap = BitmapFactory.decodeStream(in);
            view.setImageBitmap(bitmap);
            in.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // getThumbnail();
        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        Log.e("GridView", "Icons not for use");
    }
    view.setImageResource(drawables.get(position));
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setLayoutParams(new android.widget.GridView.LayoutParams(70, 70));
    view.setTag(String.valueOf(position));
    return view;
}

}
package com.example.awesomefilebuilderwidget;
进口
公共类GridViewAdapter扩展了BaseAdapter{
私人语境;
//将所有图像保留在数组列表中
public ArrayList drawables=new ArrayList();
复选框mCheckBox=null;
//建造师
公共GridViewAdapter(上下文c){
上下文=c;
Log.d(“GridViewAdapter”,“已设置构造函数”);
添加(R.drawable.pattern1);
Log.d(“GridViewAdapter”,“添加模式1”);
添加(R.drawable.pattern2);
Log.d(“GridViewAdapter”,“添加模式2”);
添加(R.drawable.trashcan);
Log.d(“GridViewAdapter”,“添加垃圾桶”);
添加(R.drawable.ic_启动器);
Log.d(“GridViewAdapter”,“添加了ic_启动器”);
}
公共无效设置复选框(复选框){
mCheckBox=复选框;
}
@凌驾
//此适配器表示的数据集中有多少项
public int getCount(){
返回drawables.size();
}
@凌驾
//获取与中指定位置关联的数据项
//数据集
公共对象getItem(int位置){
返回可抽取项。获取(位置);
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
公共布尔值可存储(){
布尔值mExternalStorageAvailable=false;
String state=Environment.getExternalStorageState();
if(环境、介质、安装等于(状态)){
//我们可以读写媒体
mExternalStorageAvailable=true;
Log.i(“可读取”,“外部存储卡可读”);
}else if(Environment.MEDIA\u MOUNTED\u READ\u ONLY.equals(state)){
//我们只能阅读媒体
Log.i(“可读取”,“外部存储卡可读”);
mExternalStorageAvailable=true;
}否则{
//还有别的问题,可能是其他许多问题之一
//但是我们需要知道的是我们既不会读也不会写
mExternalStorageAvailable=false;
}
返回mExternalStorageAvailable;
}
公共位图缩略图(){
最终字符串APP_PATH_SD_CARD=“/TEST/”;
最终字符串APP\u THUMBNAIL\u PATH\u SD\u CARD=“thumbnails”;
字符串filename=“AFBWIcon.png”;
String fullPath=Environment.getExternalStorageDirectory().getAbsolutePath()+APP\u PATH\u SD\u卡+APP\u缩略图\u PATH\u SD\u卡;
位图缩略图=空;
//在外部存储器上查找该文件
试一试{
如果(IsSdable()==true){
缩略图=位图工厂.decodeFile(完整路径+“/”+文件名);
}
}捕获(例外e){
Log.e(“外部存储器上的getThumbnail()”,e.getMessage());
}
//如果外部存储上没有文件,请查看内部存储
如果(缩略图==null){
试一试{
File filePath=Context.getFileStreamPath(文件名);
FileInputStream fi=新的FileInputStream(filePath);
缩略图=BitmapFactory.decodeStream(fi);
}捕获(例外情况除外){
e(“内部存储上的getThumbnail()”,例如getMessage());
}
}
返回缩略图;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
//尝试重用视图
ImageView视图=(ImageView)convertView;
@抑制警告(“未使用”)
布尔选中=(mCheckBox==null)?false:((复选框)mCheckBox.isChecked());
//如果convert视图为空,则创建一个新实例,否则重新使用它
如果(视图==null){
视图=新图像视图(上下文);
Log.d(“GridViewAdapter”,“新增imageView”);
}
如果(选中=真){
是可怕的;
试一试{
FileInputStream in=Context.openFileInput(“BitmapImage”);
//加载回图像文件以确认其工作
位图位图=位图工厂.decodeStream(in);
view.setImageBitmap(位图);
in.close();
}catch(filenotfounde异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
//getThumbnail();
捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}否则{
Log.e(“GridView”、“图标不可用”);
}
view.setImageResource(drawables.get(position));
view.setScaleType(ImageView.ScaleType.CENTER\U裁剪);
view.setLayoutParams(新的android.widget.GridView.LayoutParams(70,70));
view.setTag(String.valueOf(position));
返回视图;
}
}
这是我的清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.awesomefilebuilderwidget"
android:versionCode="1"
android:versionName="1.0" >

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

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

<receiver android:name="com.example.awesomefilebuilderwidget.AFBWidget" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>

<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_stuff"/>

</receiver>

<activity android:name="com.example.awesomefilebuilderwidget.WidgetConfig" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>

</intent-filter> 

</activity>   

<activity android:name="com.example.awesomefilebuilderwidget.Drag_and_Drop_App" android:label="@string/app_name" android:windowSoftInputMode="stateHidden" android:screenOrientation="portrait"></activity>
<activity android:name="com.example.awesomefilebuilderwidget.AppInfoAdapter" android:label="@string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.Feedback" android:label="@string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.GridView" android:label="@string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.SendMessageActivity" android:label="@string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.Utilities" android:label="@string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.Personalize" android:label="@string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.SwipeDetector" android:label="@string/app_name"></activity>
<activity android:name="com.example.awesomefilebuilderwidget.GridViewAdapter" android:label="@string/app_name"></activity>

</application>

</manifest> 
<activity android:name=".put your started activity name here"
              android:label="@string/app_name">
 <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

我环顾了一下SOF,但还没有找到任何有助于解决这个问题的方法。 是什么导致了这个错误


请注意,在我收到此错误之前,此操作运行良好

从清单中删除适配器类引用


您只在清单中添加活动类,因为您在清单中指定了适配器类,所以它会崩溃,请删除该类,并且您的应用程序没有默认的启动活动 在清单中需要类似的内容:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.awesomefilebuilderwidget"
android:versionCode="1"
android:versionName="1.0" >

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

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

<receiver android:name="com.example.awesomefilebuilderwidget.AFBWidget" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>

<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_stuff"/>

</receiver>

<activity android:name="com.example.awesomefilebuilderwidget.WidgetConfig" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>

</intent-filter> 

</activity>   

<activity android:name="com.example.awesomefilebuilderwidget.Drag_and_Drop_App" android:label="@string/app_name" android:windowSoftInputMode="stateHidden" android:screenOrientation="portrait"></activity>
<activity android:name="com.example.awesomefilebuilderwidget.AppInfoAdapter" android:label="@string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.Feedback" android:label="@string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.GridView" android:label="@string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.SendMessageActivity" android:label="@string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.Utilities" android:label="@string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.Personalize" android:label="@string/app_name" ></activity>
<activity android:name="com.example.awesomefilebuilderwidget.SwipeDetector" android:label="@string/app_name"></activity>
<activity android:name="com.example.awesomefilebuilderwidget.GridViewAdapter" android:label="@string/app_name"></activity>

</application>

</manifest> 
<activity android:name=".put your started activity name here"
              android:label="@string/app_name">
 <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>


指定您想要的活动

请格式化您的清单。检查我发布的答案,当我这样做时,我会得到以下错误:12-14 12:57:04.047:E/AndroidRuntime(708):android.content.ActivityNotFoundException:找不到显式活动类{com.example.awesomefilebuilderwidget/com.example.awesomefilebuilderwidget.GridViewAdapter}; 您是否在AndroidManifest.xml中声明了此活动?首先,这不是一个活动,因为它正在扩展适配器。使用此适配器从创建列表的位置发布您的类自从我将其设置为一个小部件以来,我没有这些小部件,因为当我打开小部件时,运行的不仅仅是一个主类