RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-268386

Rick Petrev's questions

Martin Hope
Rick Petrev
Asked: 2021-11-12 18:55:25 +0000 UTC

Viber 机器人无法连接

  • 0

连接服务器上的所有证书。注册了一个机器人。我从关闭的代码。文档并上传到服务器

from flask import Flask, request, Response
from viberbot import Api
from viberbot.api.bot_configuration import BotConfiguration
from viberbot.api.messages.text_message import TextMessage
import logging

from viberbot.api.viber_requests import ViberFailedRequest
from viberbot.api.viber_requests import ViberMessageRequest
from viberbot.api.viber_requests import ViberSubscribedRequest

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)

app = Flask(__name__)
viber = Api(BotConfiguration(
    name='имя',
    avatar='https://dl-media.viber.com/5/share/2/long/vibes/icon/image/0x0/130b/87c64fe73f29f2601d0f2243c4be524f688e45be0a64abbc11d479fefc1b130b.jpg',
    auth_token='токен'
))
viber.set_webhook("https://сайт:4443/bots/viber/")



@app.route('/', methods=['POST'])
def incoming():
    logger.debug("received request. post data: {0}".format(request.get_data()))
    # every viber message is signed, you can verify the signature using this method
    if not viber.verify_signature(request.get_data(), request.headers.get('X-Viber-Content-Signature')):
        return Response(status=403)

    # this library supplies a simple way to receive a request object
    viber_request = viber.parse_request(request.get_data())

    if isinstance(viber_request, ViberMessageRequest):
        message = viber_request.message
        # lets echo back
        viber.send_messages(viber_request.sender.id, [
            message
        ])
    elif isinstance(viber_request, ViberSubscribedRequest):
        viber.send_messages(viber_request.get_user.id, [
            TextMessage(text="thanks for subscribing!")
        ])
    elif isinstance(viber_request, ViberFailedRequest):
        logger.warn("client failed receiving message. failure: {0}".format(viber_request))

    return Response(status=200)

if __name__ == "__main__":
    context = ('server.crt', 'server.key')
    app.run(host='0.0.0.0', port=443, debug=True, ssl_context=context)

我收到一个错误

2020-11-12 10:40:08,864 - requests.packages.urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): chatapi.viber.com
2020-11-12 10:40:14,244 - requests.packages.urllib3.connectionpool - DEBUG - https://chatapi.viber.com:443 "POST /pa/set_webhook HTTP/1.1" 200 224
Traceback (most recent call last):
  File "webhook.py", line 24, in <module>
    viber.set_webhook("https://мойсайт:4443/bots/viber/")
  File "/usr/local/lib/python3.5/dist-packages/viberbot/api/api.py", line 29, in set_webhook
    return self._request_sender.set_webhook(url, webhook_events, is_inline)
  File "/usr/local/lib/python3.5/dist-packages/viberbot/api/api_request_sender.py", line 32, in set_webhook
    raise Exception(u"failed with status: {0}, message: {1}".format(result['status'], result['status_message']))
Exception: failed with status: 1, message: Result[HttpRequest[POST /bots/viber/ HTTP/1.1]@1b2c34c4 > HttpResponse[null 0 null]@6b5df0a3] java.util.concurrent.TimeoutException: Total timeout 5000 ms elapsed

决定添加 viber.json 文件

{
  "url": "мойсайт/bots/viber/"
}

并通过 curl 发出请求

curl -# -i -g -H "X-Viber-Auth-Token:токен" -d @viber.json -X POST https://chatapi.viber.com/pa/set_webhook -v

已收到

Warning: Couldn't read data from file "viber.json", this makes an empty POST.
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 52.44.100.16...
* TCP_NODELAY set
* Connected to chatapi.viber.com (52.44.100.16) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=*.viber.com
*  start date: Feb 13 00:00:00 2020 GMT
*  expire date: Mar 13 12:00:00 2021 GMT
*  subjectAltName: host "chatapi.viber.com" matched cert's "*.viber.com"
*  issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
*  SSL certificate verify ok.
> POST /pa/set_webhook HTTP/1.1
> Host: chatapi.viber.com
> User-Agent: curl/7.52.1
> Accept: */*
> X-Viber-Auth-Token:token
> Content-Length: 0
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< cache-control: no-cache no-store
cache-control: no-cache no-store
< content-type: application/json
content-type: application/json
< date: Thu Nov 12 05:53:32 2020
date: Thu Nov 12 05:53:32 2020
< server-time: 78wWvHUBAAA=
server-time: 78wWvHUBAAA=
< Content-Length: 73
Content-Length: 73
< Connection: keep-alive
Connection: keep-alive

<
* Curl_http_done: called premature == 0
* Connection #0 to host chatapi.viber.com left intact
{"status":4,"status_message":"missingData","chat_hostname":"SN-CHAT-03_"}

我不明白问题是什么,为什么它不启动?

python
  • 1 个回答
  • 10 Views
Martin Hope
Rick Petrev
Asked: 2020-07-31 19:04:23 +0000 UTC

Telgegram bot 图像未发送

  • 0

我遇到了图片链接没有扩展名的问题,当我尝试发送消息时

bot.send_photo(chat_id, "https://surgebook.com/uploads/user_160759/covers/1gyxx0joec_thumb_340")

崩溃一个错误

telebot.apihelper.ApiException:对 Telegram API 的请求不成功。服务器返回 HTTP 400 错误请求。响应正文:[b'{"ok":false,"error_code":400,"description":"Bad Request: wrong file identifier/HTTP URL specified"}'] " 2020-07-31 13:55:10,814

(init .py:455 MainThread)错误 - TeleBot:“对 Telegram API 的请求不成功。服务器返回 HTTP 400 错误请求。响应正文:[b'{“ok”:false,“error_code”:400, description":"错误请求:指定了错误的文件标识符/HTTP URL"}']"

如果您拍摄任何其他网址以 .jpg .png 结尾的图像,则发送成功。有什么方法可以在不下载文件的情况下解决问题?

python
  • 1 个回答
  • 10 Views
Martin Hope
Rick Petrev
Asked: 2020-05-13 20:02:12 +0000 UTC

发布 ASP.NET Core 站点

  • 0

发布网站时出错

发布遇到错误对象引用未设置为对象的实例诊断日志已写入以下位置

如果你看日志

5/13/2020 2:38:12 PM System.NullReferenceException:对象引用未设置为对象的实例。在 Microsoft.VisualStudio.ApplicationCapabilities.Publish.Provider.DefaultPublishTabProvider.InitializeProvider(IVsHierarchy 层次结构) 在 Microsoft.VisualStudio.ApplicationCapabilities.Publish.Provider.DefaultPublishTabProvider.CreateViewAsync(IVsHierarchy 项目,IAsyncServiceProvider serviceProvider,CancellationToken cancelToken) .Provider.ManagedPublishProvider.d__3.MoveNext ()

启动或构建项目时未观察到错误。更新VS没有帮助。

c#
  • 1 个回答
  • 10 Views
Martin Hope
Rick Petrev
Asked: 2020-03-18 09:53:30 +0000 UTC

Selenium 停止工作 java 浏览器

  • 0

一个可执行的 jar 文件挂在 Linux 服务器上,即 Telegram bot。该程序全天候不间断工作,解析互联网上的链接。一切工作几天(2-3天)然后发生错误

Mar 17, 2020 6:19:26 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Marionette threw an error: <unprintable error>
org.openqa.selenium.WebDriverException: java.net.SocketTimeoutException: timeout
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'autoru-1579587188088-s-1vcpu-1gb-ams3-01', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-88-generic', java.version: '1.8.0_242'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:609)
    at org.openqa.selenium.remote.RemoteWebDriver.getPageSource(RemoteWebDriver.java:438)
    at com.company.bot.bot.Parsing.WebSurfing.connect(WebSurfing.java:37)
    at com.company.bot.bot.Parsing.ParsinTop.start(ParsinTop.java:41)
    at com.company.bot.bot.Parsing.ParsinTop.run(ParsinTop.java:19)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.SocketTimeoutException: timeout
    at okio.Okio$4.newTimeoutException(Okio.java:232)
    at okio.AsyncTimeout.exit(AsyncTimeout.java:285)
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:241)
    at okio.RealBufferedSource.indexOf(RealBufferedSource.java:355)
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:227)
    at okhttp3.internal.http1.Http1Codec.readHeaderLine(Http1Codec.java:215)
    at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
    at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at org.openqa.selenium.remote.internal.OkHttpClient$Factory$1.lambda$createClient$1(OkHttpClient.java:152)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
    at okhttp3.RealCall.execute(RealCall.java:77)
    at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:103)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:155)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    ... 7 more
Caused by: java.net.SocketException: Socket closed
    at java.net.SocketInputStream.read(SocketInputStream.java:204)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at okio.Okio$2.read(Okio.java:140)
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
    ... 32 more
Mar 17, 2020 3:19:59 PM org.openqa.selenium.os.OsProcess destroy
INFO: Unable to drain process streams. Ignoring but the exception being swallowed follows.
org.apache.commons.exec.ExecuteException: The stop timeout of 2000 ms was exceeded (Exit value: -559038737)
    at org.apache.commons.exec.PumpStreamHandler.stopThread(PumpStreamHandler.java:295)
    at org.apache.commons.exec.PumpStreamHandler.stop(PumpStreamHandler.java:181)
    at org.openqa.selenium.os.OsProcess.destroy(OsProcess.java:136)
    at org.openqa.selenium.os.CommandLine.destroy(CommandLine.java:153)
    at org.openqa.selenium.remote.service.DriverService.stop(DriverService.java:232)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:95)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:609)
    at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:452)
    at com.company.bot.bot.Parsing.WebSurfing.connect(WebSurfing.java:58)
    at com.company.bot.bot.Parsing.ParsinTop.start(ParsinTop.java:41)
    at com.company.bot.bot.Parsing.ParsinTop.run(ParsinTop.java:19)
    at java.lang.Thread.run(Thread.java:748) 

之后,在我的情况下,在 geckodriver 上的 Firefox 中重新启动浏览器。重新启动后,一个新的错误飞了

Mar 17, 2020 3:19:59 PM org.openqa.selenium.os.OsProcess destroy
INFO: Unable to drain process streams. Ignoring but the exception being swallowed follows.
org.apache.commons.exec.ExecuteException: The stop timeout of 2000 ms was exceeded (Exit value: -559038737)
    at org.apache.commons.exec.PumpStreamHandler.stopThread(PumpStreamHandler.java:295)
    at org.apache.commons.exec.PumpStreamHandler.stop(PumpStreamHandler.java:181)
    at org.openqa.selenium.os.OsProcess.destroy(OsProcess.java:136)
    at org.openqa.selenium.os.CommandLine.destroy(CommandLine.java:153)
    at org.openqa.selenium.remote.service.DriverService.stop(DriverService.java:232)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:95)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:609)
    at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:452)
    at com.company.bot.bot.Parsing.WebSurfing.connect(WebSurfing.java:58)
    at com.company.bot.bot.Parsing.ParsinTop.start(ParsinTop.java:41)
    at com.company.bot.bot.Parsing.ParsinTop.run(ParsinTop.java:19)
    at java.lang.Thread.run(Thread.java:748)

Mar 17, 2020 3:19:59 PM org.openqa.selenium.os.OsProcess destroy
SEVERE: Unable to kill process java.lang.UNIXProcess@78019293

    ...

但是它没有工作,而是连续多次启动浏览器,之后发生冲突。新打开的浏览器出现错误并且不关闭,但挂起工作,重新加载服务器

org.openqa.selenium.WebDriverException: connection refused
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'autoru-1579587188088-s-1vcpu-1gb-ams3-01', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-88-generic', java.version: '1.8.0_242'
Driver info: driver.version: FirefoxDriver
remote stacktrace: 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)
    at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:486)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:531)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:147)
    at com.company.bot.bot.Parsing.WebSurfing.connect(WebSurfing.java:25)
    at com.company.bot.bot.Parsing.ParsinTop.start(ParsinTop.java:41)
    at com.company.bot.bot.Parsing.ParsinTop.run(ParsinTop.java:19)
    at java.lang.Thread.run(Thread.java:748)

执行解析和启动浏览器的类本身

public class WebSurfing extends ArrayList<String>{

    public HashMap<String, String> connect(String url){
        HashMap<String, String> hm = new HashMap<>();

        System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver"); // /usr/bin/geckodriver

        FirefoxOptions options = new FirefoxOptions();
        options.addArguments("--headless");

        WebDriver driver = new FirefoxDriver(options);

        try {
            url = url.replace("https://auto.ru/cars/", "https://auto.ru/moskva/cars/");
            driver.get(url);
            System.out.println("Connect to " + url);

            driver.findElements(By.xpath("//div[@class='button button_blue']")).get(0).click();
            System.out.println("After accept");

            Thread.sleep(10000);
            try {
               Document document = Jsoup.parse(driver.getPageSource());
               Elements elements = document.getElementsByClass("Link CardDealerName-module__dealerName");

               hm.put("Результат", elements.get(0).attr("href"));
               System.out.println(hm.get("Результат"));
               hm.put("Конкурент", elements.get(0).text());
               System.out.println(hm.get("Конкурент"));

            } catch (Exception e) {
                hm.put("Результат", " ");
                hm.put("Конкурент", " ");
                e.printStackTrace();
            }

        } catch(Exception ex){
            ex.printStackTrace();
        } finally {
            try {
                driver.close();
            } catch (Exception e){}
            try {
                driver.quit();
            } catch (Exception e){}
        }

        return hm;
    }
}

也许我做错了什么,怎么了?

java
  • 1 个回答
  • 10 Views
Martin Hope
Rick Petrev
Asked: 2020-12-26 01:11:51 +0000 UTC

解析一个java页面

  • 1

如果有“显示更多”按钮,我如何解析整个网页?用jsoup解析。屏幕截图显示了按钮的属性。

在此处输入图像描述

java
  • 1 个回答
  • 10 Views
Martin Hope
Rick Petrev
Asked: 2020-05-19 00:57:25 +0000 UTC

未创建 ItelIiJ IDEA 项目结构

  • 4

每次创建项目时,即使单击“使用主类创建”复选框resource,也不会创建项目中的某些文件夹,例如 。main

项目结构:

如何解决这个问题?

java
  • 1 个回答
  • 10 Views
Martin Hope
Rick Petrev
Asked: 2020-04-13 03:33:45 +0000 UTC

通过 SQL 查询填充表[JAVA]

  • 0

您好,我通过 rs.next() 连接数据库并显示数据,一切正常。我写了一个函数来显示表格中的值,每次我得到一个错误

ArrayIndexOutOfBoundsException: 0 >= 0

我知道索引有错误,但这并没有改变,没有任何反应

public JTable getTable(String nameTbl){
    JTable tbl = new JTable();

    String querty = "select * from " + nameTbl;
    try {
        rs = st.executeQuery(querty);
        rsmd = rs.getMetaData();

        int countCol = rsmd.getColumnCount();
        int countRow = rs.getRow();

        javax.swing.table.DefaultTableModel dtm = new javax.swing.table.DefaultTableModel();
        dtm.setRowCount(0);

        int cC = 0;
        int cR = 0;
        int n = 0;
        String[] nameColumn = new String[10];

        int c = 0;
        for(int i = 1; i <= rsmd.getColumnCount(); i++){
            nameColumn[c] = rsmd.getColumnName(i);
            c++;
        }

        while(rs.next()){
            dtm.setRowCount(dtm.getRowCount() + 1);
            if(cC < countCol){
                dtm.setValueAt(rs.getString(nameColumn[cC]), cC, cR);
                cC++;
            }
            if(cC == countCol) cC = 0;
            cR++;

        }
        tbl.setModel(dtm);

    } catch (SQLException ex) {
       System.out.println("Error " + ex);
    }
    return tbl;
}

错误的位置

dtm.setValueAt(rs.getString(nameColumn[cC]), cC, cR);
java
  • 1 个回答
  • 10 Views
Martin Hope
Rick Petrev
Asked: 2020-03-29 04:57:38 +0000 UTC

JPanel 继承

  • 0

你好,为什么不能继承面板?

 settingButt.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            PanelSett panel2 = new PanelSett();
            if(onClickSett == false) {
                panel.add(panel2);
                System.out.println("1");
                panel.repaint();
                onClickSett = true;
            }
            else{
                panel.remove(panel2);
                panel.revalidate();
                panel.repaint();
                onClickSett = false;
            }
        }
    });

1 在控制台中成功显示,但是面板没有出现

PanelSett 类

public class PanelSett extends JPanel{
public void paintComponent(Graphics g){
    this.setSize(100, 100);
    this.setBackground(Color.red);
    this.setVisible(true);
    System.out.println("2");
}} // В консоле даже 2 нет
java
  • 1 个回答
  • 10 Views
Martin Hope
Rick Petrev
Asked: 2020-01-20 04:51:09 +0000 UTC

创建 Java 文件

  • 0

您好,如何在 C 盘上创建文件?当我在 D 上做时,一切正常。当我将 D 更改为 C 时,什么也没有发生。

String path = "D:\\Program Files\\MyManager\\" + User_name + ".txt";

File file = new File(path);
file.getParentFile().mkdirs();
java
  • 1 个回答
  • 10 Views
Martin Hope
Rick Petrev
Asked: 2020-01-12 20:54:01 +0000 UTC

Swing 或 JavaFX [关闭]

  • 2
关闭。这个问题不可能给出客观的答案。目前不接受回复。

想改进这个问题? 重新构建问题,以便可以根据事实和引用来回答。

3年前关闭。

改进问题

你好,我使用Swing创建图形应用程序,我遇到了JavaFX,很多人写到Swing已经很老了,一般来说是一个村庄。Swing有什么比JavaFX更好的吗?并且有很多不同之处吗?如果切换到FX ,那么在Swing中自信地写会不会有什么困难?

java
  • 1 个回答
  • 10 Views
Martin Hope
Rick Petrev
Asked: 2020-01-02 01:26:07 +0000 UTC

将一个 jFrame 引用到另一个 jFrame 的元素

  • 0

您好,是否可以从一个 jFrame 访问另一个jFrame 的元素?

如果有,例如我有jFrame1 (这包含一个按钮)和jFrame2 (这包含一个文本字段)。单击按钮时,如何实现在文本字段中显示“Hello”的内容?

java
  • 1 个回答
  • 10 Views
Martin Hope
Rick Petrev
Asked: 2021-01-01 05:32:52 +0000 UTC

如何关闭jFrame?

  • 1

你好,这可能是一个很愚蠢的问题,但是我第一次遇到这个,所以我新开了一个jFrame

new ViewEditImage().setVisible(true);

然后我想关闭它。

所以:

new ViewEditImage().setVisible(false);

所以:

jPanel1.setVisible(false); 

没有任何效果

java
  • 1 个回答
  • 10 Views
Martin Hope
Rick Petrev
Asked: 2020-12-26 15:58:54 +0000 UTC

JTextPane 中的斜体文本

  • 0

我还创建JTextPane了一个按钮,使文本“斜体”。改成这样的字体:

jTextPane1.setFont(new Font("Courier New", Font.ITALIC, 16));

那只是整个文本的更改,而不是更改后我写的内容。我怎样才能使以前写的东西不受编辑。

在 Java 中是否可以使用选定的文本?例如,这样我选择了文本,当我点击按钮时,只有文本的选定部分会改变?

java
  • 1 个回答
  • 10 Views
Martin Hope
Rick Petrev
Asked: 2020-11-18 00:53:21 +0000 UTC

评估写入字符串的表达式

  • 2

我当时正在写一个图形计算器,想法是把整个表达式写成String,也就是说,用户用按钮输入他需要决定的内容,例如 2313 + 3435 - 53 * 2 ,它都是用String text. 是否有任何库可以实现这一点,或者关于如何做到这一点的建议?

怎么写String我知道,主要是怎么解这个方程。

在此处输入图像描述

java
  • 1 个回答
  • 10 Views
Martin Hope
Rick Petrev
Asked: 2020-11-05 07:07:43 +0000 UTC

java数组排序错误

  • 1

你好,我正在写一个数组排序。这里给出一个错误:

n = arr[i]; 

这是代码本身:

public class Main {
    public static void main(String[] args) {
        int[] arr = { 1, 2, 3, 4, 5};
        int n = 0;
        int i = 0;
        int a = 0;
        for(i = arr.length; i >= 0; i--){ // i = 4
            while(i>=0) { // i=>0
                a++; // 1, 2, 3 ,4
                for (i = i; i<=arr.length-a; i--){ // i<= 4, 3, 2 , 1, 0
                    n = arr[i]; //  n = 5
                    arr[i] = arr[i--]; // arr[4] = 4
                    arr[i--] = n; // arr[3] = 5
                }
            }
        }

        for(int s = 0; s<=arr.length; s++) {
            System.out.println(arr[s]); // 5 4 3 2 1
        }
    }

这是错误本身:

Quote: 线程“主” java.lang.ArrayIndexOutOfBoundsException 中的异常:5

我意识到数组索引有问题。所以它似乎是数组的最后一个元素,也就是在我的例子中,arr[4] = arr[arr.lenght],或者不是?

java
  • 2 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5