Error Modding minecraft 1.12.2 please guys [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 days ago.
Improve this question
Item Creation Error (public class ItemsRegistry ) The nested type ItemsRegistry cannot hide an enclosing type.
package com.thedoffee.sd.registers;
public class ItemsRegistry {
#ObjectHolder("tut")
#Mod.EventBusSubscriber
public class ItemsRegistry {
#ObjectHolder("key")
public static final Item KEY = null;
#SubscribeEvent
public static void onRegistryItem(RegistryEvent.Register<Item> e) {
e.getRegistry().register(new ItemKey());
}
#SubscribeEvent
#SideOnly(Side.CLIENT)
public static void onRegistryModel(ModelRegistryEvent e) {
//
}
}
}

Related

Write a constructor in class Doctor to initialize the private field doctor_name [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 months ago.
Improve this question
Write a constructor in class Doctor to initialize the private field doctor_name. How can I write this?
class Doctor{
public Doctor(private String doc_name){
}
}
Here is an example class Doctor with a constructor.
class Doctor{
private String doc_name;
Doctor(String doc_name){
this.doc_name = doc_name;
}
}
You can also add a setter and getter to apply encapsulation.
class Doctor{
private String doc_name;
Doctor(String doc_name) {
this.doc_name = doc_name;
}
public void setDoctorName(String doc_name) {
this.doc_name = doc_name;
}
public String getDoctorName() {
return this.doc_name;
}
}
I've made a simple implementation of the class Doctor.
class Main {
public static void main(String[] args) {
Doctor doctor1 = new Doctor("Someone");
System.out.println(doctor1.getDoctorName());
doctor1.setDoctorName("Someone Else");
System.out.println(doctor1.getDoctorName());
}
}
Output:
Someone
Someone Else

how to share a variable inside actionListener (java) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm trying to make a preference menu and trying to share a variable that is inside action listener. Thanks in advance
public void actionPerformed(ActionEvent e) {
if(e.getSource()==buttonp1) {
player_c=c1.getText();
if(player_c.equalsIgnoreCase("blue")) {
p1_color="blue";
//i want to share a String with another class.
}
if(player_c.equalsIgnoreCase("red")) {
p1_color="red";
}
if(player_c.equalsIgnoreCase("green")) {
p1_color="green";
}
}
}
Move the variable to a different class, and pass an instance to the listener (probably by lexical scope).
class Player {
private String color;
// ...
public void setColor(String color) {
this.color = Objects.requireNonNull(color);
}
}
// ...
Player p1 = ...;
// (Watch the repetition.)
blue.addActionListener(event -> {
p1.setColor("blue");
});
red.addActionListener(event -> {
p1.setColor("red");
});
green.addActionListener(event -> {
p1.setColor("green");
});
// ...

Java return Object [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I don’t know how to return the value of the string here, in short, I need the output of this string that is stored in the function:
public Object Directory(String directory) {
String directory1 = "directory";
return directory1;
}
public static void main(String... args) throws Exception {
System.out.println(directory1);
}
This is my interface in another file:
public interface Interface extends Remote {
Object FileName(String filename) throws RemoteException;
Object Directory(String directory) throws RemoteException;
}
If I understand you. You can try so.
public static String Directory(String directory) {
String directory1 = "directory";
return directory1;
}
public static void main(String... args) throws Exception {
System.out.println(Directory("directory1"));
}
In Java you must declare the return type of a function. In your case you have defined the return type of Object when you really want a return type of String

Unexpected NullPointerException [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
How can NullReferenceException happen here:
public class DataContextBinder extends Binder {
private static final String DATA_CONTEXT = "DataContext";
// Fields
private final Listener<PropertyChangedEventArgs<Object>> dataContextListener = new Listener<PropertyChangedEventArgs<Object>>() {
#Override
public void onEvent(PropertyChangedEventArgs<Object> args) {
setSource(args.getNewValue());
}
};
// Constructors
protected DataContextBinder(Object target, String targetPropertyName,
Binding binding) {
super(Property.getPropertyValue(target, DATA_CONTEXT), target,
targetPropertyName, binding);
}
// Methods
protected void createListeners(Object source) {
Log.e("DataContextBinder", "DCL = " + dataContextListener.toString());
// It throws NullPointerException on dataContextListener.toString()
Property.addPropertyChangedListener(getTarget(), DATA_CONTEXT,
dataContextListener);
super.createListeners(source);
}
protected void removeListeners(Object source) {
Property.removePropertyChangedListener(getTarget(), DATA_CONTEXT,
dataContextListener);
super.removeListeners(source);
}
}
dataContextListener is null..

How do I write the class that contains the main function for this code? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
public class Soldier
{
private String soldierName;
public void setSoldierName( String name )
{
SoldierName = name;
}
public String getSoldierName()
{
return soldierName;
}
public void displayMessage()
{
System.out.printf( "The name of \n%s!\n",
getSoldierName() );
}
}
If you just want the class to have a main method, just add it as you would to any other class:
public class Soldier
{
private String soldierName;
public void setSoldierName( String name )
{
SoldierName = name;
}
public String getSoldierName()
{
return soldierName;
}
public void displayMessage()
{
System.out.printf( "The name of \n%s!\n",
getSoldierName() );
}
public static void main(String args[]) {
}
}
To actually do something useful in the main, you might want to create an instance of the class in there, set the soldier name and then call the displayMessage() method, for example. So like this:
public static void main(String args[]) {
Soldier soldier = new Soldier();
soldier.setSoldierName("John");
soldier.displayMessage();
}

Categories