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);
Related
The app is crashing when the app is in the background and I changed the font and open the app again.
Getting Below error
Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment could not find Fragment constructor
Steps
Open the bottom sheet dialog CategoriesBottomSheetDialog
Minimize the application (in the background)
Changed font
Open the app again
I can provide a fix using bundle but I want to know if using kotlin plugin no-arg concept can apply this annotation on CategoriesBottomSheetDialog and allow the class to be invoked with the empty constructor.
#NoArg
class CategoriesBottomSheetDialog(
override val di: DI,
screenType: MainScreenType
) : DIAware, BottomSheetDialogFragment() {}
I tried but not working even though the root cause is unable to invoke an empty constructor. Any inputs on this note to kind of solve without using bundle?
I am trying to set the color of the ActionBar while my app is "minimized" using the TaskDescription as suggested by the answer to this post: Setting header color of app in overview (recent apps) screen
Here is the relevant code:
...
import android.app.ActivityManager;
...
public class MainActivity extends SherlockFragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
...
int c = Color.parseColor("#0A782F");
ActivityManager.TaskDescription td = new ActivityManager.TaskDescription(R.string.app_name, R.drawable.launcher, c);
((SherlockFragmentActivity) this).setTaskDescription(td);
}
...
}
Although I have not posted the xml resource files for this project, you may assume that R.string.app_name and R.drawable.launcher are defined in xml files.
Here's the problem: when I compile this code, I get the following error:
error: cannot find symbol
...
symbol: class TaskDescription
location: class MainActivity
Now, from what I understand, Java throws the cannot find symbol error when you refer to a class or variable name that does not exist. In the case of classes, it is usually caused by forgetting to import the class you need. However, that cannot be the cause in this case, as I have clearly imported ActivityManager at the top of my class file.
Here are some other examples where people have done exactly the same things, just to show that I have done my research: http://www.programcreek.com/java-api-examples/index.php?class=android.app.ActivityManager&method=TaskDescription
Finally, I thought the problem might have been that you can only instantiate the TaskDescription class in an Activity context. However, I am using SherlockFragmentActivity instead of the standard AppCompatActivity. Unfortunately, I tried changing this and I still get the same error. Any ideas?
Thanks in advance for your help!
Found the solution! I didn't mention in the problem that I had built my project using gradle. The issue was that I was using an old Sdk version (in particular, I was using a version of the android Sdk which had not yet defined the TaskDescription class). Therefore, to fix the problem, all I had to do was add the following line to the appropriate place in my build.gradle file:
compileSdkVersion 21
Hope this helps someone else who is feeling lost for the same reason.
I am creating simple video player application which play video from URL and live stream.
I use the following code for player video. Everything is fine but I am unable to resolve the problem of this line in below code:
" com.android.internal.policy.PolicyManager mWindow=
PolicyManager.makeNewWindow(mContext); "
It shows the error message
com.android.internal.policy.PolicyManager cannot be resolved to a type
in android
How to resolve this error?
mWindow = PolicyManager.makeNewWindow(mContext);
You can't.
The mWindow = PolicyManager.makeNewWindow(mContext);
returns Window not
com.android.internal.policy.PolicyManager
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.
Situation:
I have a TextView that have the property
android:textAlignment="center"
I am generating another TextView dinamically, based on my TextView from XML Layout, using a clone, cloning all the basic properties to work the way above.
Problem:
To do this i need to use this method:
this.myTextView.setMyTextViewProperty(MyTextView.getMyTextViewProperty());
for example:
this.MyTextView.setText(MyTextView.getText());
Note that this.MyTextViewis a local variable and MyTextView is a private var declared on the top of the file, under class name.
I do this on all the properties of the TextView but when i hit the following line of code from the TextAlignment property...:
this.myTextView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
I tried to set it to a Custom Aligment instead of getting from my XML TextView It gives me an error:
11-20 15:27:04.460: E/AndroidRuntime(9185): FATAL EXCEPTION: main
11-20 15:27:04.460: E/AndroidRuntime(9185): java.lang.NoSuchMethodError: android.widget.TextView.setTextAlignment
But i see on Ctrl + Space that the method exists, so i cant understand what is happening.
A second try was, to set my TextView property to the property that comes from my TextView:
this.myTextView.setTextAlignment(MyTextView.getTextAlignment());
With no success, too.
Obs: i do not want a Android XML Layout solution, i want a solution on code, because i generate the TextView dinamically on the Activity
I'm using API Level 15
Any help?
The setTextAlignment method was added in API level 17. Maybe your compiler in the IDE is above 17 and the device/emulator which you are testing is less than that. Here the link to setTextAlignment.
Added from the comments:
For API level 15 and below, you want setGravity, per this question.