本文介绍了无法实例接收器没有空的构造的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要当用户激活互联网进行操作,但我得到了以下错误:

java.lang.InstantiationException:无法实例类com.project.proj.NetworkChangeReceiver;没有空的构造

在一个活动类我写了下面的

  NetworkChangeReceiver净值=新NetworkChangeReceiver(getBaseContext());

我要去哪里错了。请帮助!

 公共类NetworkChangeReceiver扩展广播接收器
 {
    上下文mContext;
    公共NetworkChangeReceiver(上下文的背景下)
    {
        mContext =背景;
     }    @覆盖
    公共无效的onReceive(最终上下文的背景下,最终的意图意图){        字符串状态= NetworkUtil.getConnectivityStatusString(背景);
如果(状态==WLAN网络)
{
    数据库信息=新的数据库(mContext);
    details.open();
    清单<串GT; detailsId;
    detailsId = details.getRecords();
    retrieveValues​​FromListMethod1(detailsId);
    Toast.makeText(背景下,正常工作,Toast.LENGTH_SHORT).show();
}
        Toast.makeText(上下文,状态Toast.LENGTH_SHORT).show();
    }
公共无效retrieveValues​​FromListMethod1(名单detailsId)
{    迭代器ITR = detailsId.iterator();
    而(itr.hasNext())
    {
    //做一点事    }
}
}


解决方案

删除:

 上下文mContext;
公共NetworkChangeReceiver(上下文的背景下)
{
    mContext =背景;
 }

I want to perform operation when the user has internet activated but i get the following error :

java.lang.InstantiationException: can't instantiate class com.project.proj.NetworkChangeReceiver; no empty constructor

In an activity class i have written the following

NetworkChangeReceiver net = new NetworkChangeReceiver(getBaseContext());

where am I going wrong. Please help !

public class NetworkChangeReceiver extends BroadcastReceiver
 {
    Context mContext;
    public NetworkChangeReceiver(Context context)
    {
        mContext= context;
     }

    @Override
    public void onReceive(final Context context, final Intent intent) {

        String status = NetworkUtil.getConnectivityStatusString(context);
if (status == "Wifi enabled")
{
    Database details=new Database(mContext);
    details.open();
    List<String> detailsId;
    detailsId=details.getRecords();
    retrieveValuesFromListMethod1(detailsId);
    Toast.makeText(context, "working properly", Toast.LENGTH_SHORT).show();
}
        Toast.makeText(context, status, Toast.LENGTH_SHORT).show();
    }


public void retrieveValuesFromListMethod1(List detailsId)
{

    Iterator itr = detailsId.iterator();
    while(itr.hasNext())
    {
    //do something

    }
}
}
解决方案

Remove:

Context mContext;
public NetworkChangeReceiver(Context context)
{
    mContext= context;
 }

这篇关于无法实例接收器没有空的构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 06:25