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..
Related
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) {
//
}
}
}
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
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");
});
// ...
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
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a problem finding a solution for this peculiar problem.
I have this class of a generic Stack.
class Pilita<T> {
private int tam;
private T[] arregloPila;
private int tope;
#SuppressWarnings("unchecked")
public Pilita(int tam) {
this.tam=tam;
arregloPila=(T[])new Object[tam];
tope=-1;
}
public void push(T valor){
if(pilaLlena()){
throw new StackFullException("No se puede meter el: "+"["+valor+"]"+" La pila esta llena");
}
arregloPila[++tope]=valor;
}
public T pop() {
if(pilaVacia()){
throw new StackEmptyException("La pila esta vacia");
}
return arregloPila[tope--];
}
public boolean pilaVacia(){
return (tope == -1);
}
public boolean pilaLlena(){
return (tope==tam-1);
}
public int contar(){
return(tope+1);
}
And I want to know how to implement a method to print the stack, because i have a method for normal stacks, but it doesn't seems to work with Generic Stack.
Any help would be Helpful.
To print the all the stack, you only need to check if the stack is not empty
public static void main(String[] args) {
Pilita pila = new Pilita(3);
pila.push("1");
pila.push("2");
pila.push("3");
while (!pila.pilaVacia()) {
System.out.println("Pil pop " + pila.pop());
}
}