简体   繁体   English

“ InstantiationException:零参数构造函数” --->怎么做?

[英]“InstantiationException: zero argument constructor” ---> How to do it?

I have already read things about that but can't find a way to fix my problem anyway (Beginner here...) So, I'm currently developping an Android Studio App. 我已经读过有关此内容,但无论如何都找不到解决我的问题的方法(在这里是初学者...)因此,我目前正在开发一个Android Studio应用程序。 I have just done fragments to have different tab on a screen. 我刚刚完成了片段操作,以便在屏幕上显示不同的标签。 Previously I have done a "bluetooth and a bluetoothService" activity who was perfectly working. 以前,我已经完成了一个“蓝牙和bluetoothService”活动,该活动运行得很好。 However, since I have implements these fragments I got this error 但是,由于我已经实现了这些片段,所以出现了此错误

 java.lang.InstantiationException: java.lang.Class<com.example.thibaud.dogbotapp.bluetoothService> has no zero argument consde here

So I have tried to do an empty constructor but I don't know how to do it properly... 所以我试图做一个空的构造函数,但是我不知道如何正确地做...

This is the begin of my bluetoothService class : 这是我bluetoothService类的开始:

public class bluetoothService  {


private static final String TAG = "bluetoothService";

private static final String appName = "DogBot";

private static final UUID MY_UUID_INSECURE =
        UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

private final BluetoothAdapter btAdapter;



Context mContext;

private AcceptThread mInsecureAcceptThread;

private ConnectThread mConnectThread;
private BluetoothDevice mmDevice;
private UUID deviceUUID;
ProgressDialog mProgressDialog;

private ConnectedThread mConnectedThread;


/*public bluetoothService(Context context) {
    mContext = context;
    btAdapter = BluetoothAdapter.getDefaultAdapter();
    start();
}*/

start() method here : start()方法在这里:

 public synchronized void start() {
    Log.d(TAG, "start");

    // Cancel any thread attempting to make a connection
    if (mConnectThread != null) {
        mConnectThread.cancel();
        mConnectThread = null;
    }
    if (mInsecureAcceptThread == null) {
        mInsecureAcceptThread = new AcceptThread();
        mInsecureAcceptThread.start();
    }
}

Well, first post here sorry if it's not perfect, hope you guys will be able to help ! 好吧,在这里先发帖抱歉,如果它还不够完善,希望你们能够为您提供帮助! Thanksar Thanksar

A zero-argument constructor is declared like so: 零参数构造函数的声明如下:

public ClassName() {
//Constructor tasks go here
}

Hope it helps 希望能帮助到你

EDIT: 编辑:

And yes, as davidxxx stated, you should always start class names with upper case letters. 是的,正如davidxxx所说,您应该始终以大写字母开头类名。 eg ClassName as opposed to className . 例如ClassName而不是className Variable names, however, start with lower case such as variableName . 但是,变量名以小写开头,例如variableName

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.InstantiationException:类没有零参数构造函数错误 - java.lang.InstantiationException: class has no zero argument constructor error 为什么我得到“java.lang.InstantiationException 没有零参数构造函数”? - Why am I getting "java.lang.InstantiationException has no zero argument constructor"? Xamarin Android java.lang.InstantiationException:java.lang.Class没有零参数构造函数 - Xamarin Android java.lang.InstantiationException: java.lang.Class has no zero argument constructor java.lang.RuntimeException:无法实例化活动…java.lang.InstantiationException:类没有零参数构造函数 - java.lang.RuntimeException: Unable to instantiate activity… java.lang.InstantiationException: class has no zero argument constructor 自定义视图 class 正在抛出:java.lang.InstantiationException: java.lang.Z9BD81329FEDFDEFE0AF2 没有78个零参数构造函数 - Custom View class is throwing: java.lang.InstantiationException: java.lang.Class has no zero argument constructor java.lang.InstantiationException: java.lang.Class<com.wavedevelopers.eventsplanning.BookingForm> 没有零参数构造函数 - java.lang.InstantiationException: java.lang.Class<com.wavedevelopers.eventsplanning.BookingForm> has no zero argument constructor 缺少零参数构造函数 - Missing Zero Argument Constructor CollapsingTitleLayout没有零参数构造函数 - CollapsingTitleLayout has no zero argument constructor AndroidViewModel 没有零参数构造函数。 如何解决这个问题? - AndroidViewModel has no zero argument constructor. How to solve this? 视图-没有零参数构造函数 - View - Has no zero argument constructor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM