which library I have to include in my eclipse to use Thread.sleep() - myeclipse

I want to use in my code : "Thread.sleep(10000);" in my esclipe
in netbeans it worked and I just included:
"import java.io.;
import java.net.;"
so what should i do in myeclipse to use it
thank u

You just need to make sure you handle any exceptions that could arise. Adding a try/catch statement will do the trick:
try {
Thread.sleep(500);
} catch(InterruptedException e) {
Thread.currentThread().interrupt();
}
Hope this helps!

Related

Jetpack Compose preview stopped working in Arctic Fox with Patch 1

With the first patch for AS Arctic Fox Jetpack Compose previews stopped working.
I'm getting this error for all previews - even older ones, which worked fine a while back:
android.content.res.Resources$NotFoundException: Could not resolve resource value: [some hex value]
Are here any quick fixes for this? Clearing caches and the usual stuff did not work.
EDIT:
Looks like the problem is not always present. Some preview started working, while other are still failing.
EDIT 2:
This is happening in dynamic feature modules, when there's a need for resources from the main module or painterResource() is being used (even is resource from the same module is to be displayed).
Same problem here with dynamic-modules project.
Inspired by above answer, I've made another temporary workaround while waiting for Compose team to fix this.
import androidx.compose.ui.res.stringResource as originalStringResource
#Composable
#ReadOnlyComposable
fun stringResourceSafe(#StringRes id: Int): String =
if (BuildConfig.DEBUG) {
val resources = LocalContext.current.resources
try {
resources.getString(id)
} catch (e: Resources.NotFoundException) {
"missing res."
}
} else {
originalStringResource(id)
}
This got fixed in AS Bumblebee, patch 2.
As a temporary hack workaround I did this to get past the error and preview the UI elements.
//import androidx.compose.ui.res.stringResource
fun stringResource(id: Int): String {
when (id) {
R.string.res_id -> return "Foo"
...
}
return "missing res_id"
}

Dagger2 ApplicationComponent not generated(git project included)

So I'm trying to follow Googles architecture example and my daggerappcomponent is not generating. I tried changing up the gradle files but I'm not sure what I'm doing wrong. First time doing something "advanced" like this(for me at least). I commented out everything from the DI package as I cannot get it working without the QuoteApplication, and I cant get QuoteApplication working without building the project and hoping it will generate necessary dagger files.
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
return DaggerApplicationComponent.factory().create(applicationContext) //here is the problem
}
Here's the project https://github.com/Nikola-Milovic/QuoteAppMvvm
I tried a lot of different build gradles and I tried cleaning rebuidling and so on. I've read all of the online fixes but nothing has worked. I'm certain it's my fault but it might be a bug or something. My last resort is to ask here. Kinda stuck at this.
It worked perfeclty fine for me.
I build.
The component is generated.
The buld fails because no import.
I import the newly created component. (import com.example.quoteappmvvm.di.DaggerApplicationComponent)
It works.
package com.example.quoteappmvvm
import com.example.quoteappmvvm.di.DaggerApplicationComponent >>>> You need this!!!
import dagger.android.AndroidInjector
import dagger.android.support.DaggerApplication
//open class QuoteApplication{
//// override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
////
//// return DaggerApplicationComponent.factory().create(applicationContext)
//// }
//
//// override fun onCreate() {
//// super.onCreate()
//// // if (BuildConfig.DEBUG) Timber.plant(DebugTree())
//// }
//}
open class QuoteApplication : DaggerApplication() {
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
return DaggerApplicationComponent.factory().create(this)
}
override fun onCreate() {
super.onCreate()
// if (BuildConfig.DEBUG) Timber.plant(DebugTree())
}
}

Annoying error "Missing method: public TypeOfResult ..."

I have a DoFixture in the package be.acred.b2c.ws.creditRequest.service.MyFixture
When I run a test using Fitnesse I get the following error message.
Missing method: public TypeOfResult
getBeDotAcredDotB2cDotWsDotCreditRequestDotServiceDotMyFixture() { }
OR: public TypeOfResult
beDotAcredDotB2cDotWsDotCreditRequestDotServiceDotMyFixturee() { }
in class be.acred.b2c.ws.creditRequest.service.MyFixture
I can see that I'm not the only one having that problem but I can't find a solution on the Web.
Ok, I could as well define that method in my fixture, but I'd like to understand why it's there and if there is any cleaner way to get rid of that error.
Any help would be greatly appreciated.
Here's the page code. The same structure works fine when I'm using a ColumnFixture instead of a DoFixture.
!*> Classpath
!pomFile C:\Users\otonglet\WORKSPACES\b2c\pom.xml#test
*!
!|be.acred.b2c.ws.creditRequest.service.MyFixture|
|init_request|1250.00|
|form_data|{some json data}|language|en_us|
|send_request|en_us|
|show|key|

Checking if control exists throws an error

Really what I am after is a way to check if the control exists without throwing an error.
The code should look something like this:
Control myControl = UIMap.MyMainWindow;
if (!myControl.Exists)
{
//Do something here
}
The problem is that the control throws an error because it is invalid if it doesn't exist, essentially making the exists property useless.
What is the solution?
In this case I am using the tryfind method.
Like this:
HtmlDiv list = new HtmlDiv(Window.GetWebtop());
list.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
list.SearchProperties.Add(HtmlDiv.PropertyNames.InnerText, "Processing search", PropertyExpressionOperator.Contains);
if (list.TryFind())
{
//DO Something
}
I am re-posting the comment kida gave as a answer, because I think its the best solution.
Control myControl = UIMap.MyMainWindow;
if (!myControl.FindMatchingControls().Count == 0)
{
//Do something here
}
The FindMatchingControls().Count is much faster then the Try Catch or the TryFind. Since it does not wait for SearchTimeoutto check if the element is now there. Default it waits 30 seconds for the element to not be there, but I like my tests to fail fast.
Alternatively its possible to lower the Playback.PlaybackSettings.SearchTimeout before the Catch or TryFind and restore it afterwards, but this is unnecessary code if you ask me.
You can do one of two things: Wrap your code in a try-catch block so the exception will be swallowed:
try
{
if (!myControl.Exists)
{
// Do something here.
}
}
catch (System.Exception ex)
{
}
Or, you could add more conditions:
if (!myControl.Exists)
{
// Do something here.
}
else if (myControlExists)
{
// Do something else.
}
else
{
// If the others don't qualify
// (for example, if the object is null), this will be executed.
}
Personally, I like the catch block, because if I expect the control to be there as part of my test, I can Assert.Fail(ex.ToString()); to stop the test right there and log the error message for use in bug reporting.
If you are sure that control will exist or enabled after some time you can use WaitForControlExist() or WaitForControlEnabled() methods with a default timeout or specified timeout.
I have a situation like this and I am looping until the control is available :
bool isSaveButtonExist = uISaveButton.WaitForControlEnabled();
while (!isSaveButtonExist )
{
try
{
uISaveButton.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
uISaveButton.SetFocus(); // setting focus for the save button if found
isSaveButtonExist = uISaveButton.WaitForControlExist(100);
}
catch (Exception ex)
{
//Console.WriteLine(ex.Message); // exception for every set focus message if the control not exist
}
}
// do something with found save button
// Click 'Save' button
Mouse.Click(uISaveButton, new Point(31, 37));
please refer to this link for more about these Methods:
Make playback wait methods

How could I use pointcut in C# using AOP

I have developed a Application using pointcut(AOP Around) in java.i.e.
pointcut ps(String s,int iTemp1,int iTemp2) :
call (void java.awt.Graphics.drawString(String,int,int)) && args(s,iTemp1,iTemp2);
void around(String s,int i1,int i2) : ps(s,i1,i2)
{
if(flag1)
{
try
{
//Some code
}
catch(Exception ex)
{
}
}
s=image_applet.foo(s);
if(flag2)
{
try
{
//code
}
catch(Exception ex)
{
}
}
proceed(s,iTemp1,iTemp2);
}
and I want to develop same pointcut in our methods which is used in my c# code.If it is possible den please give me some directions.
I've used Spring.NET's AOP implementations with great success - maybe that could work for you?
Checkout the NKalore project #
http://aspectsharpcomp.sourceforge.net/
There are loads of AOP spoofs in .NET including the handicapped Code Contracts. However to my knowledge NKalore is the only one that mirrors AspectJ grammar and patterns. Other frameworks like LinFu, post sharp (starter edition) require you to place attributes and follow a different pattern. There is no AOP grammar support because they lack AOP compilers.

Resources