在Python中,我试图在类中运行一个方法,我得到一个错误:
Traceback (most recent call last):
File "C:\Users\domenico\Desktop\py\main.py", line 8, in <module>
fibo.f()
TypeError: unbound method f() must be called with fibo instance
as first argument (got nothing instead)
Run Code Online (Sandbox Code Playgroud)
代码:(swineflu.py)
class fibo:
a=0
b=0
def f(self,a=0):
print fibo.b+a
b=a;
return self(a+1)
Run Code Online (Sandbox Code Playgroud)
脚本main.py
import swineflu
f = swineflu
fibo = f.fibo
fibo.f() #TypeError is thrown here
Run Code Online (Sandbox Code Playgroud)
这个错误是什么意思?导致此错误的原因是什么?
我正在尝试LinearLayout从另一个类更改一个,但是当我运行此代码时:
public class IRC extends PircBot {
ArrayList<String> channels;
ArrayList<Integer> userCount;
ArrayList<String> topics;
LinearLayout channelLayout;
Context context;
public IRC(Context ctx) {
this.setName("xxxx");
channels = new ArrayList<String>();
userCount = new ArrayList<Integer>();
topics = new ArrayList<String>();
context = ctx;
channelLayout = (LinearLayout) ((Activity) context).findViewById(R.id.channels);
}
Run Code Online (Sandbox Code Playgroud)
我得到了 ClassCastException
context是Activity使用getApplicationContext()传递的main活动;
logcat的
05-08 17:53:55.102 3736-3799/g.d.allinonechat E/AndroidRuntime? FATAL EXCEPTION: Thread-5357
java.lang.ClassCastException: android.app.Application cannot be cast to android.app.Activity
at g.d.xxx.IRC.<init>(IRC.java:34)
at g.d.xxx.MainActivity$1.run(MainActivity.java:49)
at java.lang.Thread.run(Thread.java:856)
Run Code Online (Sandbox Code Playgroud) 我已经创建了一个游戏,在桌面模式下它可以,但是当我在S3上启动它时,它会进入横向模式,我该如何更改?
先感谢您
我使用Intellij Idea在Windows中使用Java(FX)开发了一个程序,并且运行得很好,然后我导出了工件(jar),在Windows上运行它没有问题(使用控制台并双击它).
然后我将它复制到我的Ubuntu VM,但它说
Error: Could not find or load main class sample.Main
Run Code Online (Sandbox Code Playgroud)
这是清单:
Manifest-Version: 1.0
Main-Class: sample.Main
Run Code Online (Sandbox Code Playgroud)
JAR文件结构如下所示:
test.jar
--- META-INF
--- --- MANIFEST.MF
--- org
--- --- json
--- --- --- // json library
--- sample
--- --- Contacts.class
--- --- Controller.class
--- --- Main.class
--- --- sample.fxml
Run Code Online (Sandbox Code Playgroud) 我在数据库中有一个视图表,我正在尝试使用以下代码更新其中的记录(或者如果尚不存在则创建它):
$ar = ['number_of_views' => $number_of_views['number_of_views']+1, 'post_id' => $post->id];
App\View::updateOrCreate(['id' => $number_of_views['id']], $ar);
Run Code Online (Sandbox Code Playgroud)
不幸的是这会返回一个错误:
SQLSTATE[HY000]: 一般错误: 1364 字段 'post_id' 没有默认值 (SQL: 插入
views(number_of_views,updated_at,created_at) 值 (1, 2017-02-09 14:41:19, 2017-02-09 14 :41:19))
似乎它无法识别,'post_id' => $post->id因此返回错误,就好像根本没有设置一样。
仅当要创建记录时才会出现此错误,如果记录已存在则不会出现此错误。
什么时候有必要?
(对于冗余数据,我的意思是多个表中的相同数据)
谷歌表示,必须进行5次网络往返,并且在前3次往返之后,只有18%的内容可以查看.
我怎样才能改善这个?
谢谢.
这个程序没有使用所有的CPU功率.我期待它能够接管cpu并尽可能快地运行代码,但它最多只能使用10个
#include <iostream>
using namespace std;
int main(void) {
unsigned long long x = 600851475143;
unsigned long long i = x-1;
while(i <= x) {
cout << "\r";
cout << i;
if((x % i) == 0) {
cout << "\n\n";
cout << i;
break;
}
i--;
}
system("pause");
}
Run Code Online (Sandbox Code Playgroud)
它最多只能达到10%
在我的 MariaDB 中,我有一个名为
“帖子”与
id, title, username_id, text, image_url, url
Run Code Online (Sandbox Code Playgroud)
一个称为“标签”的
id, tag
Run Code Online (Sandbox Code Playgroud)
一个名为 post_tags 的
id, post_id, tag_id。
我想要完成的事情是从“帖子”表中获取 3 个帖子,这些帖子与页面上当前显示的帖子具有最多的共同标签。
我被困在这里不知道从哪里开始。
编辑
Posts
id | username_id | title | text | image_url | url
1 1 example example_text localhost/image.jpg localhost/first-post
2 1 example1 example_text localhost/image1.jpg localhost/second-post
3 1 example2 example_text localhost/image2.jpg localhost/third-post
4 1 example4 example_text localhost/image4.jpg localhost/fourth-post
... ... ... ... ... ...
... ... ... ... ... ...
Tags
id | tag
1 herbs
2 …Run Code Online (Sandbox Code Playgroud) 我正在尝试从数据库中检索数据,我需要将 sql 作为原始查询运行,这就是我的做法:
$var = Nuti::select(DB::raw("select name, image, info from nuti
where name like '%:search_term%'"), array("search_term" => $term));
return $var;
Run Code Online (Sandbox Code Playgroud)
$var 返回一个空数组,但是当我尝试直接在 mysql 控制台中运行相同的查询时,它返回两条记录。
[编辑]
当我发布这个问题时,我只是缩短了查询,原始查询的需要是做更多这样的事情:
$var = Nuti::select(DB::raw("select name, image, info from nuti
where name like '%:search_term%'") or info %like% '%:search_term%', array("search_term" => $term));
return $var;
Run Code Online (Sandbox Code Playgroud)