during execution master detail flow i get 2 errors 1-Error:(77, 24) error: cannot find symbol class ItemListActivity - android-studio

public static class SimpleItemRecyclerViewAdapter
extends RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> {
private final ItemListActivity mParentActivity;
private final List<DummyContent.DummyItem> mValues;
private final boolean mTwoPane;
private final View.OnClickListener mOnClickListener = new View.OnClickListener() {
#Override
public void onClick(View view) {
DummyContent.DummyItem item = (DummyContent.DummyItem) view.getTag();
if (mTwoPane) {
Bundle arguments = new Bundle();
arguments.putString(WebpageDetailFragment.ARG_ITEM_ID, item.id);
WebpageDetailFragment fragment = new WebpageDetailFragment();
fragment.setArguments(arguments);
mParentActivity.getSupportFragmentManager().beginTransaction()
.replace(R.id.webpage_detail_container, fragment)
.commit();

This happens when you change the default item names during the wizard of creating the activity.
just rename the ItemListActivity to the name of your Activity . ( the name of the file that has that code error).
use refactor rename to change it everywhere it's mentioned.

If the ItemListActivity (or whatever you ended up calling it) extends from Activity and not AppCompatActivity then try changing the line
mParentActivity.getSupportFragmentManager().beginTransaction()
to
mParentActivity.getFragmentManager().beginTransaction()

Related

'this' is not available in variables android studio

I have a class to take data from a database and every time I create a variable in the debug mode the name of the variable appears with the message 'this' is not available and I cannot save any type of data in it.
public class DatosPerfilUsuario {
RequestQueue requestQueue;
SharedPreferencias sharedPreferencias = new SharedPreferencias();
String[] StringSplit;
public void RetirarPerfilUsuario(final Context context, final ImageView imageView, final EditText nombre, final EditText nombreusuario, final EditText sexo, final EditText edad, final EditText email, final EditText bio){
StringRequest getRequest = new StringRequest(Request.Method.POST, DatosBase.CONEXION_DB_RETIRAR_PERFILUSUARIO, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
if(response.equals("0")){
}else {
StringSplit = response.split("/");
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
}) {
protected Map<String,String> getParams(){
Map<String, String> params = new HashMap<String, String>();
params.put("NombreUsuario",sharedPreferencias.obtenerValorString(context,"Usuario").toLowerCase());
return params;
}
};
requestQueue = Volley.newRequestQueue(context);
requestQueue.add(getRequest);
}
Code
This situation happens to me with each type of variable that I create int, string, bool ...
I have different classes that do the same, but the problem only arises in this.
I have looked for a solution to the problem in google but there is very little information about this problem, if someone has the solution or understands why this problem is due I would appreciate your help.
UPDATED
It looks like this is not preventing you from compiling and running the code, only that you can't view the variable's contents in the debug window. Sorry. This is not uncommon. The debugger can't determine the this in the current context.
It looks like you may be using Android Studio? If so, check this: https://stackoverflow.com/a/37273436/12431728
OLD / WRONG
Your Response.Listener<String> is an anonymous class, so this refers to the anonymous class. Since StringSplit is a field of the outer class, you should be able to access it as:
OuterClassName.this.StringSplit = ...
Where OuterClassName is the name of the class that contains this code (and StringSplit).

Problem with custom processing button to generate NoteIDs

Creating a new dummy maintenance screen to enable universal search on item cross references and gotten as far as creating the new DAC and BLC, even adding the Processing buttons to the screen, but when clicking the either processing button nothing happens (currently have it throwing a PXException). Ultimately I need to use the "Process All" (labeled "Create NoteIDs") button to fill in the NoteID field so I can actually work on the universal search part.
This is my graph. The INItemXRef is actually a new custom DAC with a NoteID field attached (no other changes, created directly from the database). Ultimately I need to update the code below to fill in random values to empty NoteIDs, so if there is any advice on the next step that would also be appreciated after solving the immediate problem:
public class INItemXRefGraph : PXGraph<INItemXRefGraph>
{
public PXSelect<INItemXRef> INItemXRef;
public PXSave<INItemXRef> Save;
public PXFilter<INItemXRef> MasterView;
[PXFilterable]
public PXProcessing<INItemXRef, Where<INItemXRef.noteID, IsNull>> INDocumentList;
public INItemXRefGraph()
{
INDocumentList.SetProcessDelegate(ReleaseDoc);
INDocumentList.SetProcessAllCaption("Create NoteIDs");
}
public static void ReleaseDoc(System.Collections.Generic.List<INItemXRef> list)
{
throw new PXException("Hello World");
}
Try this
public class INItemXRefGraph : PXGraph<INItemXRefGraph>
{
public PXSelect<INItemXRef> INItemXRef;
public PXSave<INItemXRef> Save;
public PXFilter<INItemXRef> MasterView;
[PXFilterable]
public PXProcessing<INItemXRef, Where<INItemXRef.noteID, IsNull>> INDocumentList;
public INItemXRefGraph()
{
INDocumentList.SetProcessDelegate(
delegate(System.Collections.Generic.List<INItemXRef> list)
{
System.Collections.Generic.List<INItemXRef> newlist = new System.Collections.Generic.List<INItemXRef>(list.Count);
foreach (INItemXRef doc in list)
{
newlist.Add(doc);
}
ReleaseDoc(newlist);
}
);
INDocumentList.SetProcessAllCaption("Create NoteIDs");
}
public static void ReleaseDoc(System.Collections.Generic.List<INItemXRef> list)
{
throw new PXException("Hello World");
}

Referencing JRadioButtons in ActionListener

I am trying to write a GUI that displays a hex value and it's associated color based on whichever JRadioButton is selected. My ActionListener looks up a hashMap entry that stores the individual radio buttons as an object key and it's associated hex value (as a string).
I can get the hex values with the hashMap.get pieces, but how do I get the action listener to reference any JRadioButton rather than just 'jrbBlue' or whatever is hard-coded?
Eclipse doesn't like it if I put JRadioButton.addActionListener(Error - "Cannot make a static reference to the non-static method addActionListener(ActionListener) from the type AbstractButton") or jpRadioButton.addActionListener, my JPanel for the buttons (it wants to change addActionListener to addComponentListener and a bunch of other addWhatevers, none of which work).
I realize there are other ways to write this whole thing, but I'm tying to work with what I have and I'm still learning.
Thanks in advance.
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
public class Colors extends JFrame {
static Map<Object, String> hashMap = new HashMap<Object, String>();
String hex = "Hex Value";
//---- The JLabel message (hex value of the color selected)
private JLabel jlblMessage = new JLabel(hex, JLabel.CENTER);
//---- Create the radio buttons
private static JRadioButton jrbBlue = new JRadioButton("Blue");
private static JRadioButton jrbPurplish = new JRadioButton("Purplish");
private static JRadioButton jrbRed = new JRadioButton("Red");
private static JRadioButton jrbYellow = new JRadioButton("Yellow");
private static JRadioButton jrbGreen = new JRadioButton("Green");
private static JRadioButton jrbOrange = new JRadioButton("Orange");
private static JRadioButton jrbCyan = new JRadioButton("Cyan");
private static JRadioButton jrbCoral = new JRadioButton("Coral");
private static JRadioButton jrbFuscia = new JRadioButton("Fuscia");
private static JRadioButton jrbViolet = new JRadioButton("Violet");
private static JRadioButton jrbDodgerBlue = new JRadioButton("Dodger Blue");
private static JRadioButton jrbGrey = new JRadioButton("Grey");
private static JRadioButton jrbWhite = new JRadioButton("White");
private static JRadioButton jrbCrimson = new JRadioButton("Crimson");
private static JRadioButton jrbDarkOrchid = new JRadioButton("Dark Orchid");
private static JRadioButton jrbFirebrick = new JRadioButton("Firebrick");
private static JRadioButton jrbHotPink = new JRadioButton("Hot Pink");
private static JRadioButton jrbMaroon = new JRadioButton("Maroon");
private static JRadioButton jrbDarkBlue = new JRadioButton("Dark Blue");
private static JRadioButton jrbTurquoise = new JRadioButton("Turquoise");
public Colors() {
//---- JLabel placement
jlblMessage.setBorder(new LineBorder(Color.BLACK, 2));
add(jlblMessage, BorderLayout.CENTER);
//---- Add the radio buttons to the JPanel
JPanel jpRadioButtons = new JPanel();
jpRadioButtons.setLayout(new GridLayout(3, 1));
jpRadioButtons.add(jrbBlue);
jpRadioButtons.add(jrbPurplish);
jpRadioButtons.add(jrbRed);
jpRadioButtons.add(jrbYellow);
jpRadioButtons.add(jrbGreen);
jpRadioButtons.add(jrbOrange);
jpRadioButtons.add(jrbCyan);
jpRadioButtons.add(jrbCoral);
jpRadioButtons.add(jrbFuscia);
jpRadioButtons.add(jrbViolet);
jpRadioButtons.add(jrbDodgerBlue);
jpRadioButtons.add(jrbGrey);
jpRadioButtons.add(jrbWhite);
jpRadioButtons.add(jrbCrimson);
jpRadioButtons.add(jrbDarkOrchid);
jpRadioButtons.add(jrbFirebrick);
jpRadioButtons.add(jrbHotPink);
jpRadioButtons.add(jrbMaroon);
jpRadioButtons.add(jrbDarkBlue);
jpRadioButtons.add(jrbTurquoise);
add(jpRadioButtons, BorderLayout.WEST);
//---- Add all the buttons to the same group
ButtonGroup group = new ButtonGroup();
group.add(jrbBlue);
group.add(jrbPurplish);
group.add(jrbRed);
group.add(jrbYellow);
group.add(jrbGreen);
group.add(jrbOrange);
group.add(jrbCyan);
group.add(jrbCoral);
group.add(jrbFuscia);
group.add(jrbViolet);
group.add(jrbDodgerBlue);
group.add(jrbGrey);
group.add(jrbWhite);
group.add(jrbCrimson);
group.add(jrbDarkOrchid);
group.add(jrbFirebrick);
group.add(jrbHotPink);
group.add(jrbMaroon);
group.add(jrbDarkBlue);
group.add(jrbTurquoise);
//jrbBlue.setSelected(true);
//jlblMessage.setForeground(Color.decode("#0000FF"));
//---- Action Listener
jrbBlue.addActionListener(new ActionListener() { //<---- How to Reference whichever button is selected?
#Override
public void actionPerformed(ActionEvent e) {
jlblMessage.setForeground(Color.decode("#000000"));
jlblMessage.setText(hashMap.get((JRadioButton)e.getSource()));
getContentPane().setBackground(Color.decode(hashMap.get((JRadioButton)e.getSource())));
}
});
}
public static void main(String[] args) {
Colors frame = new Colors();
frame.pack();
frame.setTitle("Colors");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(900,300);
//---- Color library map
hashMap.put(jrbBlue, "#0000FF");
hashMap.put(jrbPurplish, "#DF01D7");
hashMap.put(jrbRed, "#FF0000");
hashMap.put(jrbYellow, "#FFFF00");
hashMap.put(jrbGreen, "#00FF00");
hashMap.put(jrbOrange, "#FF8C00");
hashMap.put(jrbCyan, "#00FFFF");
hashMap.put(jrbCoral, "#FF7F50");
hashMap.put(jrbFuscia, "#FF00FF");
hashMap.put(jrbViolet, "#00FF00");
hashMap.put(jrbDodgerBlue, "#1E90FF");
hashMap.put(jrbGrey, "#C0C0C0");
hashMap.put(jrbWhite, "#FFFFFF");
hashMap.put(jrbCrimson, "#DC143C");
hashMap.put(jrbDarkOrchid, "#9932CC");
hashMap.put(jrbFirebrick, "#B22222");
hashMap.put(jrbHotPink, "#FF69B4");
hashMap.put(jrbDarkBlue, "#00008B");
hashMap.put(jrbMaroon, "#800000");
hashMap.put(jrbTurquoise, "#48D1CC");
}
}
Write a single action listener and add it to all required radio buttons. Then inside actionPerformed(ActionEvent e), you can call e.getSource(). This returns the corresponding JRadioButton, so you can cast it and use it. No need to hardcode variables inside the action listener.

Actionbarsherlock : How to "keep" it in 1 class

I'm completely new to Java and Android..
While using actionbarsherlock, I'm having a problem that I can't solve.
My app has around 8 Activities in total, and each of them has the SAME action bar,
using ABS.
So I was wondering if there is a way to keep the whole ABS part in 1 class,
and then call it in other activities when needed. Or else, I would have to write the same code in each activity to reach the same action bar, which really doesn't look correct.
I remember before using ABS, I had to use a separate row in XML then inflate it in other activities when needed. But this whole ABS project seems too vast for a newbie like me and I'm
really getting confused.. can any one help me clarify? Thanks in advance.
Use a base class which sets up the action bar.
public abstract class BaseActivity extends SherlockFragmentActivity {
#Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar ab = getSupportActionBar();
ab.whatever....
}
}
And then in your activities...
public class MySweetActivity extends BaseActivity {
#Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.whatever);
}
}

Pass object from one scene to another

As I'm learning the new world of JavaFX2 I stumbled on another annoying problem. I'm developing a program with multiple scenes (~10 scenes). For that I created a small class like this:
public class SceneSelector {
...
public void setScene(Stage stage, String fxmlfilename, ObservableList ol) throws Exception{
String s = "../" + fxmlfilename;
Parent root = FXMLLoader.load(getClass().getResource(s));
root.setUserData(ol);
Scene scene = new Scene(root);
stage.setScene(scene);
//show the stage
stage.show();
}
}
This class works good enough for switching between the scenes.
Now the problem is that I sometimes need to pass data from Scene1 to Scene2. I'm trying to do this by setting the setUserData() for the new scene which basicly works exept for one thing. How can I get the userdata when the new Scene is beeing initialized? (because the Nodes are still null at that time)
Code at scene1:
//Code connected to a button that opens the new Scene
private void openLabID(ActionEvent event) throws Exception {
final Stage primaryStage = (Stage) btnNewScene.getScene().getWindow();
ObservableList<Koe> olAfTeWerkenKoeien = DA_Koe.getAfTeWerkenKoeien();
ss.setScene(primaryStage, "GUI/scenes/koe/Koe.fxml", olAfTeWerkenKoeien);
}
Code at scene2:
public void initialize(URL url, ResourceBundle rb) {
Scene s = lbl.getScene();
ObservableList<Koe> olAfTeWerkenKoeien = (ObservableList<Koe>) s.getRoot().getUserData();
System.out.println(olAfTeWerkenKoeien.size());
}
Of course Scene s gives a null value at this point (because lbl is null at this point), so I wonder, is there a method that is beeing fired right after initialize?
When I attach this code to a button on Scene2, it works like a charm, but it should be loaded automatically.
EDIT:
The setting of the data with the setMyData() method is not a problem, however retrieving it is:
public ObservableList<Koe> getMyData() {
return this.myData;
}
How can I get the CustomScene object when a controller initializes? Because doing this below will result in a NullPointerException (because btnSluiten is not initialized just yet):
#Override
public void initialize(URL url, ResourceBundle rb) {
...
Stage stage = (Stage) btnSluiten.getScene().getWindow();
CustomScene cs = (CustomScene) stage.getScene();
ObservableList<Koe> olKoe = cs.getMyData();
System.out.println(olKoe.size());
}
I believe you missed the point within the Scene object. From the Scene class documentation we can see that:
The JavaFX Scene class is the container for all content in a scene graph.
Which means that the Scene object is just a container and as such it's not supposed to hold any data.
With that in mind, you can make another static object with a field such as
private static Label lbl;
...
public static Label getLbl()
{
return MyStaticObject.Lbl;
}
...
and use it to store your lbl (or whatever object suits your information) and then statically retrieve it.
I'm doing that to set the owner of my other Stage objects from my application. I hope it helps. Cheers
If you really want your scene to be meaningful (aka store specific user data) you can extend it:
public class FooScene extends Scene {
private ObservableList myData;
public setMyData(ObservableList data) {
this.myData = data;
//handle data
}
}
The easiest way to make sure setup code is called after scene initialized it to call it by yourself:
public class SceneSelector {
...
public void setScene(Stage stage, String fxmlfilename, ObservableList ol) throws Exception{
String s = "../" + fxmlfilename;
Parent root = FXMLLoader.load(getClass().getResource(s));
// first: add root to scene
FooScene scene = new FooScene(root);
// second: apply data to scene (or root)
scene.setMyData(ol);
stage.setScene(scene);
//show the stage
stage.show();
}
}
You can use controller for scenes and pass the data through controller:
String filePath1 = "../" + fxmlfilename;
URL location1 = YourController1.class.getResource(filePath1);
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(location1);
fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
Parent root = (Node) fxmlLoader.load(location1.openStream());
YourController1 ctrl1 = (YourController1) fxmlLoader.getController();
Then you can assign data to the controller:
ctrl1.setUserData();
Finally, just show the scene as you want:
Scene scene = new Scene(root);
stage.setScene(scene);
//show the stage
stage.show();
In the initialize() method in the controller, just get data from controller as usual data object.
Some Addition of #Sergey Grinev :
Create A custom Scene :
package sample;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class DataPassingScene extends Scene {
public DataPassingScene(Parent parent) {
super(parent);
}
String tafsir;
public String getTafsir() {
return tafsir;
}
public void setTafsir(String tafsir) {
this.tafsir = tafsir;
}
}
Suppose your Main Class Name is App.java, Then Create a method to show new Stage :
public static void showLayout (Stage primaryStage, String fxmlFileName, String stringData) throws IOException {
Parent root = FXMLLoader.load(Objects.requireNonNull(App.class.getClassLoader().getResource(fxmlFileName)));
DataPassingScene scene = new DataPassingScene(root);
scene.setTafsir(stringData); // Here we pass the data
primaryStage.setScene(scene);
primaryStage.show();
}
Now When you want to pass the Data, Call the above method from any Where / any class in your app with some Data :
String tafsir = "This My Data" ;
try {
App.showLayout(new Stage(), "showTafsirFxml.fxml",tafsir);
} catch (IOException e) {
e.printStackTrace();
}
Then Get the data in your controller. To get the scene you have to get the stage, and to get the stage you have use one of your elements of FXML, suppose here your element is a button, called closeButton, So :
#FXML
private Button closeButton;
#Override
public void initialize(URL url, ResourceBundle rb) {
Platform.runLater(new Runnable() {
#Override public void run() {
Stage stage = (Stage) closeButton.getScene().getWindow();
DataPassingScene scene = (DataPassingScene) stage.getScene();
String s = scene.getTafsir(); // Here we get the Data
if(s!=null)
System.out.println("This is Tafsir From Highlight Table: "+s);
else
System.out.println("Data Passing Null");
}});
}
because, You have to wait some Times in above runLater, because for initializing scene take some time. Other wise scene will be null.

Resources