Why isn't ArrayList<>.add() working? - java

I'm new to Java and I'm currently using Android Studio. I just can't understand why .add isn't working. Subject and Assignments are just custom classes. The issue is that the message "Cannot resolve symbol 'add'" pops up and the whole thing fails. I have imported java.util.ArrayList.
ArrayList<Subject> mSubjects = new ArrayList<Subject>();
Subject cheese = new Subject("Cheese",new Assignment[]{new Assignment("Test 1",1.0f,1.0f,1.0f),new Assignment("Test 2",100f,100f,1.0f)},100f,4.0f);
mSubjects.add(cheese);

mSubjects.add(cheese);
put this method in your onCreate method.

Related

How to move from a AbilitySlice to a Ability in HarmonyOS?

I am trying to move from an AbilitySlice to an Ability. I tried the below code,
But was it not working as expected.
Operation systemOperation = new Intent.OperationBuilder()
.withBundleName(getBundleName())
.withAbilityName(MainAbility.class.getSimpleName())
.build();
intent.setOperation(systemOperation);
startAbility(intent);
for moving from an AbilitySlice to Ability in Harmony OS?
Try to Delete Simple from getSimpleName. Like following:
Operation systemOperation = new Intent.OperationBuilder()
.withBundleName(getBundleName())
.withAbilityName(MainAbility.class.getName())
.build();
intent.setOperation(systemOperation);
startAbility(intent);
"Not working as expected" generally is not a valid error description. I'd suspect the AbilitySlice might belong to MainAbility and the whole operation might therefore be pointless, as navigation from A to B could not happen. The example which #Gowtham provided has one small difference (which appears to consider the device on which to launch the Intent with Super Device):
.withDeviceId("")
Have you ever tried to start anything else but MainAbility?
I see that you have mentioned that the package name of your target ability is different than the package name of your ability slice in your reply to #Martin.
Then, you need to make sure the bundleName(or package name) specified in the Intent's Operation builder is having the target ability's package name and not the calling ability's/abilityslice's package name.
Operation systemOperation = new Intent.OperationBuilder()
.withBundleName("enter_package_name_of target_ability_here")
.withAbilityName(MainAbility.class.getName())
.build();
intent.setOperation(systemOperation);
startAbility(intent);

Unity AndroidJavaObject not working without showing errors

I have been trying to call a Java method in unity. Not working for me, even the simplest example from the docs
using System.Collections;
using UnityEngine;
public class ExampleClass : MonoBehaviour {
void Start () {
AndroidJavaObject jo = new AndroidJavaObject ("java.lang.String", "some string");
int hash = jo.Call<int> ("hashCode");
Debug.Log ("hash=" + hash);
}
}
Unity console prints hash=0, which is not the hash code for provided String. Even if I change and use java.lang.StringInvalidClass as class name, unity still reports same result to the console without notifying errors. I can even try to call toString, toStringa, toInvalid2 and they always return empty string without showing errors.
This is a brand new 2d project with only script displayed above, attached to camara object. I am using Ubuntu, Unity 2019.4 and project platform is Android.
Thanks for the assistance.
Answering myself after some time working with unity.
All examples in the web and unity documentation doesn't mention it, which is weird since it is something simple to mention and about confusions: code needs to run as an android application. Editor or even unity remote does not work, in order to use AndroidJavaObject and related classes, your code needs to run as an android application installed in the phone.

Deprecated with(Context) method

I'm new to android.
I'm trying to select the file and read it in android java. To choose a file, I'm using https://android-arsenal.com/details/1/6982 file chooser library.
But it's showing that .with(this) is deprecated. What I can replace it with to get rid of the warning?
Screenshot of warning: https://imghostr.com/xapXZzqE
Literally just scroll down that page a bit and take a look at this:
New calling chain
1.1.7+, new constructor ChooserDialog(context) can simplify the chain invoking, such as:
new ChooserDialog(this)
.withFilter(true, false)
.withStartFile(startingDir)
...

Trouble using cardslib with existing Eclipse Android project

I'm trying to use this card library for the UI of the Android app I'm trying to build, but I'm running into some problems.
The author has this guide for using the library with an existing Eclipse project which I've followed throughly, but I'm getting multiple errors.
I'm importing the library as an "Existing project" under the Import options in Eclipse, and including the project in my existing project's build path, but I keep getting errors regarding missing methods (specifically the getContext() argument specified in the constructor), even after importing the entire library.
Here is a snippet of my code:
import it.gmariotti.cardslib.library.internal.Card;
import it.gmariotti.cardslib.library.internal.CardHeader;
public class MainActivity extends Activity {
Card card = new Card(getContext());
CardHeader header = new CardHeader(getContext());
card.addCardHeader(header);
CardView cardView = (CardView) getActivity().findViewById(R.id.carddemo);
cardView.setCard(card);
I get the following errors for each respective line in my code snippet:
The method getContext() is undefined for the type MainActivity
The method getContext() is undefined for the type MainActivity
Multiple markers at this line
- Syntax error on token(s), misplaced construct(s)
- Syntax error on token "header", VariableDeclaratorId expected after
Multiple markers at this line
- CardView cannot be resolved to a type
- CardView cannot be resolved to a type
- The method getActivity() is undefined for the type
MainActivity
Multiple markers at this line
- Syntax error on token "card", VariableDeclaratorId expected after
this token
- Syntax error on token(s), misplaced construct(s)
I know this is a very specific question, but I'm hoping I can get an answer here!
Your error has nothing to do with Cardslib. Card construction accepts Context of your current Activity. There's no function as getContext() in Android. The correct function is getBaseContext().
There are two ways to send it.
Card card = new Card(getBaseContext());
or
Card card = new Card(this);

Using NetBeans, getting a cannot find symbol error where I am using setVisible

I have seen all of the posts on this site regarding the cannot find symbol error and none of them answered my question so here I am. To give you a better idea of what I am doing, I am creating a video store program that will send messages to a server which will send messages to a database and back and forth.
I have a class called login.java, a class called VideoStoreApp and a class called VideoStoreView. In my login.java class I have an if statement that is called to;
VideoStoreApp test = new VideoStoreApp();
test.setVisible(true);
I have an error at setVisible that says "class not found" and it prompts me to create a method inside videostoreapp called setvisible... I have used setVisible in my other classes with no problem. I also get the same error here if I use .show. Basically I am making a login screen pop up and then the main program appears but as of now both appear at the same time. I used super.setVisible(false) to make the login screen go away which actually worked, but as you know the main program was still visible the entire time behind that.
if (user.equals("employee") && pwd.equals("password") || user.equals("manager") && pwd.equals("password"))
{
super.setVisible(false); // no error here
VideoStoreApp test = new VideoStoreApp();
test.setVisible(true); // cannot find symbol
}
else.....
and in my main I have no errors...
...
login appear = new login();
appear.setVisible(true);
launch(VideoStoreApp.class,args);
...
Its my first time posting here guys so if I did something wrong I am sorry, I just really need help on getting this working.
entire project below;
http://paste.bradleygill.com/index.php?paste_id=281691
http://paste.bradleygill.com/index.php?paste_id=281692
''http://paste.bradleygill.com/index.php?paste_id=281693
VideoStoreApp does not contain setVisible, and it appears that neither does SingleFrameApplication, the class that you extend VideoStoreApp from.
Did you possibly mean VideoStoreApp.showMain();?

Categories