小编Dan*_*Dan的帖子

按位左移行为

今天我正在学习左移位操作符(<<).据我所知,左移位操作符按指定向左移动位.而且我知道转移乘以2.但我很困惑,就像"移位"究竟是什么意思一样,为什么当用不同的类型赋值时输出会有所不同?

当我调用下面的函数时,它输出为 System.out.println("b="+b); //Output: 0

而我的问题是:b如何变为0,为什么b被类型化?

public void leftshiftDemo()
{
    byte a=64,b;
    int i;
    i=a << 2;
    b=(byte)(a<<2);
    System.out.println("i="+i); //Output: 256    i.e 64*2^2
    System.out.println("b="+b); //Output: 0   how & why b is typecasted
}
Run Code Online (Sandbox Code Playgroud)

更新(新疑点):

它是什么意思"如果你将1位移到高位(位31或63),该值将变为负数".例如.

public void leftshifHighOrder()
{
    int i;
    int num=0xFFFFFFE;

    for(i=0;i<4;i++)
    {
        num=num<<1;
        System.out.println(num);
        /*
         * Output:
         * 536870908
         * 1073741816
         * 2147483632
         * -32   //how this is -ve?
         */
    }
}
Run Code Online (Sandbox Code Playgroud)

java bitwise-operators

5
推荐指数
1
解决办法
8294
查看次数

Selenium Webdriver - FirefoxDriver问题:错误:无法打开显示:: 0.0

我在selenium中创建了一个测试用例,它自动打开Firefox并进行登录.我通过Eclipse使用java编程实现了这一点.我测试它在我的windows7系统中工作正常.

现在,问题是一个cron作业在服务器中启动同一个程序,在尝试打开firefox时会抛出以下错误:

Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
 ------------- Standard Error -----------------
 org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055       after 45000 ms. Firefox console output:
 Error: cannot open display: :0.0
 Error: cannot open display: :0.0

    at             org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnectio n.java:118)
    at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:250)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:197)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:99)
    at com.lo.test.selenium.AssignCampaignTestCase.<clinit>(AssignCampaignTestCase.java:42)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:266)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:375)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:1420)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:848)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1899)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:800)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at …
Run Code Online (Sandbox Code Playgroud)

java junit selenium

5
推荐指数
1
解决办法
1万
查看次数

显示每个RecyclerView项目后如何检测

我想在显示给用户后在RecylerView中检测每个项目。

基本上,我试图在每个项目加载到屏幕上后播放声音。

But I am not able to detect whenever each item is loaded on the screen! Is there any method I have to call to detect each item rendered

E.g 1st RecyclerView item displayed -> play sound
    2st RecyclerView item displayed -> play sound...
Run Code Online (Sandbox Code Playgroud)

My Adapter class looks like this -

public class AdapterListAnimation extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<Multiples> items = new ArrayList<>();

    private Context ctx;
    private OnItemClickListener mOnItemClickListener;
    private int animation_type = 0;
    .........
    .........
Run Code Online (Sandbox Code Playgroud)

I …

java android android-viewholder recycler-adapter android-recyclerview

5
推荐指数
2
解决办法
3931
查看次数

如何在电子商务网站中整合Paypal支付

我已经建立了一个书店网站.我的所有工作都已完成.现在我被困在"付款"部分.我必须像这个网站一样实施Paypal支付.

我阅读了Paypal开发者页面.但究竟我找不到任何正确的文件来实现Paypal支付.

我已经制作了自己的购物车.如果用户点击结账,则应将其转发至Paypal进行付款.

请帮我提一下与上述链接类似的付款整合建议.

php codeigniter paypal

4
推荐指数
1
解决办法
7891
查看次数

Java/Struts2:如何从当前URL获取动作名称

我有一个活动页面,其网址就像 http://localhost:8085/projectName/namespace1/namespace2/namespace3/sell.action?id=22

现在我想获取动作名称(符号后面的第4个名称/)即setuppageforwared.

怎么做到这一点?请帮助我知道,因为我读了很多struts2的书,我找不到任何解决这个问题的东西.

在我使用PHP框架之前codeigniter,使用uri段功能轻松解决这类问题 (点击这里) .我在Struts2中面向同样的方面.


给定Url字符串:http://localhost:8085/projectName/namespace1/namespace2/namespace3/sell.action?id=22

预期产出:sell

java struts2

3
推荐指数
1
解决办法
1万
查看次数

Angular JS:ng-repeat没有显示价值

我是Angular JS的新学员.请帮我找一下这个演示 只显示的原因: {{cust.name| uppercase}} - {{cust.city| lowercase}}而不是显示每个值,

完整代码

    <div>
            <!-- Placeholder for views -->
            <div data-ng-view=""></div>
        </div>
        Name: <input type="text" data-ng-model="name"/>   
        <br/>
        <h3>Looping with the help of ng-repeat directive</h3>
        <ul>  
            <li data-ng-repeat="cust in customers| filter:name | orderBy:'name'"> {{cust.name| uppercase}} - {{cust.city| lowercase}} </li>
        </ul>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
        <script type="text/javascript">


var app = angular.module('app', []);

                app.config(function ($routeProvider) {
                    $routeProvider.when('/',
                            {
                                controller: 'SimpleController',
                                templateUrl: 'view1.html'
                            })
                            .when('/view2',
                                    {
                                        controller: 'SimpleController',
                                        templateUrl: 'view2.html'
                                    })
                            .otherwise({redirectTo: '/'})
                });
                app.controller('SimpleController', ['$scope', function ($scope) …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

3
推荐指数
1
解决办法
1035
查看次数

无法与TTS同步显示在recyclerVIew中的imageView

当TTS(文本到语音)播放所有可用列表项时,我如何在recyclerView中显示/隐藏imageView,一一播放!

活动方法 -该方法称为r,带有循环(不起作用,没有错误,但根本没有给出我的预期输出

    int position=0;
    public void convertTextToSpeech() {
        Multiples multiples1=items.get(position);
        for (Multiples item : items) {

            text = item.first + "  " + item.getSecond() + " Za " + item.getResult() + ".";
            tts.speak(text, TextToSpeech.QUEUE_ADD, null);
            boolean speakingEnd = tts.isSpeaking();

            if (speakingEnd) {
                Toast.makeText(getApplicationContext(), "Speaking...."+position, Toast.LENGTH_SHORT).show();
                multiples1.setImage_show(true);
                mAdapter.notifyItemChanged(position);
            } else {
                Toast.makeText(getApplicationContext(), "Done...."+position, Toast.LENGTH_SHORT).show();
            }
            position++;
        }
    }
Run Code Online (Sandbox Code Playgroud)

下面是完整的代码,以供您进一步了解,

首先,我在recyclerView中显示了所有项目。之后,我在具有for循环到TTS的方法中调用显示的项目来播放每行(列表项目)。我现在面临的问题是,由于TTS正在读取每个recyclerView项目,因此无法显示imageView。

预期的输出是每行项目的TTS播放textView时,应同时显示imageView(#image1)




尝试码更新

DisplayActivityResultAdapter.java

    ......
    .......
    int position = 0;
    public void convertTextToSpeech() {
        Multiples multiples1=items.get(position);
        for (Multiples item : items) …
Run Code Online (Sandbox Code Playgroud)

java android text-to-speech android-recyclerview

3
推荐指数
1
解决办法
506
查看次数

无法在Click事件上调用jquery函数

我有一个div我正在运行for循环.这是根据字段中的行数创建以下div.

<div class="parent">
                <p style=" font-family: Times New Roman;color:#a0a0a0; ">
                        Content 1 goes here.........
                </p>
                <div class="child">
                        <span> <a class="likebtn">Like</a> </span>1 people like this     
                </div>
            <hr/>
 </div> 
Run Code Online (Sandbox Code Playgroud)

上面显示的div位于for-each循环中,即创建多个具有相同内容的div,其上包含不同的内容.

现在我试图调用我的jquery函数,如果用户点击任何类似按钮驻留在div中.我尝试了以下功能,但我的功能没有接到电话.请帮帮我,为什么这个问题.

<script type="text/javascript">         
        $('.parent .child .likebtn').click(function(e)
        { 
            alert("function called");
        });
</script>
Run Code Online (Sandbox Code Playgroud)

有一件事,div是动态创建的,如果我在for-each循环之后编写上面的javascript代码,那么我的函数就会被调用.在Controller中编写javascript函数并不是一个好习惯.我正在使用COdeigniter框架.Plase帮助我,我必须在头部或身体中指定此功能

javascript php jquery

2
推荐指数
1
解决办法
211
查看次数

如何禁用锚标记的默认CSS颜色

是否可以使用jquery / css删除锚标记的默认CSS。
我允许用户选择 不同的jquery主题 。这就是我必须删除锚标记的默认颜色/ css的原因。这样做的原因是,如果我为锚标签使用一种固定颜色,那么如果用户选择它就不适用于其他主题,这就是我要删除锚标签的默认颜色的原因。

这是我正在使用的标签:

  <h2 class="post-title">
    <a href="">  Blog post title </a>  <!-- How to disable the default css color of anchor -->
 </h2> 
Run Code Online (Sandbox Code Playgroud)

如果我在锚点上使用CSS,那么这不适合我的其他主题。这就是原因,我想删除锚标签的默认CSS颜色。

您可以在此图中看到我当前所选主题的当前不匹配默认锚定行为,

在此处输入图片说明

请帮助我解决此问题3。

html jquery

1
推荐指数
1
解决办法
4714
查看次数

java:在同一个类中运行线程方法

我有三个threads在同一个类ie Thread A obj, Thread B obj, Thread C obj,那个类包含3 static synchronized methods所以当我们start3个线程saya.meth1,b.meth2,c.meth3 会发生什么 - 这三个都会执行还是只执行一个?

更新:面试官问我这个问题,所以实际上我有任何代码在这里写

java multithreading

1
推荐指数
1
解决办法
129
查看次数