我是android数据库开发的新手.下面的代码是我的第一个代码.执行此代码后,我在数据库表中看到没有插入任何内容.我的代码出了什么问题?
这是我的dbHelper类:
public class DbHelper extends SQLiteOpenHelper{
public DbHelper(Context context) {
super(context, "shit.db", null, 1);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "create table users (userID integer primary key autoincrement,name text,family text,age integer);";
Log.d("Ehsan", sql);
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
}
Run Code Online (Sandbox Code Playgroud)
这是我主要活动的onCreate方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("Ehsan", "Started");
DbHelper db = new DbHelper(this);
Log.d("Ehsan", "DB …Run Code Online (Sandbox Code Playgroud) 目前我正在使用pycharm来开发python web应用程序.我想用QT框架开发桌面应用程序.我已经安装了pyqt.我在pyqt中搜索了hello world并找到了这个:
from PyQt4 import QtGui, QtCore
class Window(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.button = QtGui.QPushButton('Test', self)
self.button.clicked.connect(self.handleButton)
layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.button)
def handleButton(self):
print ('Hello World')
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)
但是我不知道在哪里放这个代码?这是我的pyqt设计师看起来像:

是否可以告诉我在哪里编写代码以及如何处理按钮单击?
我想知道是否有工具来混淆整个Cordova/Phonegap项目?我的意思是整个js文件,它们彼此相关,并且与html和css文件相关.我很难一个接一个地去做.
我有一个Web服务来检索转换为字符串的图像,并在我的Android应用程序中转换回二进制数组.但不幸的是在停止时有一个强制关闭错误.
我正在使用这里解释的代码来填充imageView:
显示来自byteArray的图像
这是我在C#中的Web服务方法,它向我发送数据:
public String GetPersonImage()
{
int PersonCode = 1;
JPerson person = new JPerson(PersonCode);
Image personImage = person.PersonImage;
if (personImage == null)
return "Nothing";
using (MemoryStream ms = new MemoryStream())
{
personImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return Convert.ToBase64String(ms.ToArray());
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我试图将我的数据放入ImageView的方式:
String pic = t.execute().get();
byte[] picData = pic.getBytes();
ImageView imgPerson = (ImageView) findViewById(R.id.imgPerson);
Bitmap bitmap = BitmapFactory.decodeByteArray(picData, 0, picData.length);
imgPerson.setImageBitmap(bitmap);
Run Code Online (Sandbox Code Playgroud)
pic变量包含来自Web服务的数据.这是我的原木猫:
11-13 14:08:23.092: D/dalvikvm(29229): GC_FOR_ALLOC freed 2290K, 41% free 8004K/13420K, paused 27ms, total 27ms
11-13 14:08:23.092: I/dalvikvm-heap(29229): …Run Code Online (Sandbox Code Playgroud) 我正在使用urllib2来请求URL并读取它们的内容,但遗憾的是它不能用于某些URL.看看这些命令:
#No problem with this URL
urllib2.urlopen('http://www.huffingtonpost.com/2014/07/19/todd-akin-slavery_n_5602083.html')
#This one produced error
urllib2.urlopen('http://www.foxnews.com/us/2014/07/19/cartels-suspected-as-high-caliber-gunfire-sends-border-patrol-scrambling-on-rio/')
Run Code Online (Sandbox Code Playgroud)
产生的第二个URL和错误如下:
Traceback (most recent call last):
File "D:/Developer Center/Republishan/republishan2/republishan2/test.py", line 306, in <module>
urllib2.urlopen('http://www.foxnews.com/us/2014/07/19/cartels-suspected-as-high-caliber-gunfire-sends-border-patrol-scrambling-on-rio/')
File "C:\Python27\lib\urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 410, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 448, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 531, in …Run Code Online (Sandbox Code Playgroud) 我想读取以文本格式存储在 5GB 文件中的数据。当我尝试使用此代码读取文件内容时:
file = open('../data/entries_en.txt', 'r')
data = file.readlines()
Run Code Online (Sandbox Code Playgroud)
发生错误:data = file.readlines() MemoryError 我的笔记本电脑有 8GB 内存,当我想运行程序时,至少有 4GB 是空的。但是当我监控系统性能时,当python使用大约1.5GB的内存时,就会发生这个错误。
我正在使用 python 2.7,但如果重要,请告诉我 2.x 和 3.x 的解决方案我应该怎么做才能读取这个文件?
我正在开发一个带有Phonegap的应用程序.我想在点击另一个div时显示div.当我使用选择器$('div.show_answer') 没有任何反应,但$('div')它没关系.看看我的代码:
$(document).ready(function () {
$('div.show_answer').click(function (e) {
$(".answer").toggle();
});
});
Run Code Online (Sandbox Code Playgroud)
我的HTML:
<div class="card">
<div class="item item-text-wrap puzzle_header">
{{puzzle.name}}
</div>
</div>
<div class="card">
<div class="item item-text-wrap">
{{puzzle.question}}
</div>
</div>
<a href="" class="button button-balanced icon-left ion-star show_answer">Show answer</a>
<div class="show_answer">Show answer</div>
<div class="card answer">
<div class="item item-text-wrap">
{{puzzle.answer}}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
以上HTML文件作为视图加载到Index.html中:
<!DOCTYPE html>
<html ng-app="app">
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta …Run Code Online (Sandbox Code Playgroud) 我在另一个固定宽度的 div 中有一个 div。我希望内部 div 可以水平增长,直到 in 可以在一行中包含它的所有元素或文本。创建水平滚动条无关紧要。我该怎么办?这是我的示例代码:
<div style="width:400px;border:solid 1px red;">
TEST TEXT
<div style="border:solid 3px green;position:absolute;z-index:99;text-overflow:">
TEST INSIDE TEST INSIDE TEST INSIDE TEST INSIDE TEST INSIDE
TEST INSIDE TEST INSIDE TEST INSIDE TEST INSIDE TEST INSIDE
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我想让JSON从弹性搜索中获取查询.我使用此代码来构建查询:
search_doc = {}
search_doc.update({"sort": [{"re_max": {"order": "desc"}}]})
search_doc.update({"from": 0})
search_doc.update({"size": 100})
search_doc.update({"filter": {"and": [{"term": {"country_id": "10"}},{"range": {"pub_date": {"gte": "2014-06-07T00:00:00.0", "lte": "2014-06-07T23:59:59.0"}}}]}})
Run Code Online (Sandbox Code Playgroud)
如你所见,我在所有字符串中都使用了双引号,但请查看打印结果:
{'sort': [{'re_max': {'order': 'desc'}}], 'filter': {'and': [{'term': {'country_id': '10'}}, {'range': {'pub_date': {'gte': '2014-06-07T00:00:00.0', 'lte': '2014-06-07T23:59:59.0'}}}]}, 'from': 0, 'size': 100}
Run Code Online (Sandbox Code Playgroud)
所有单引号都是JSON格式无效或至少是弹性搜索都不接受它.有没有办法让我的字符串以有效的JSON格式?我认为这不是用双引号替换单引号的好方法.如果有办法,请帮助我.
我有一个文本文件,其中包含以 UTF-8 格式存储的 json 数据,如下所示:
\n\n{\'name\': u\'\xd8\xa7\xd8\xad\xd8\xb3\xd8\xa7\xd9\x86\', \'family\': u\'\xd8\xb4\xdb\x8c\xd8\xb1\xd8\xb2\xd8\xa7\xd8\xaf\xdb\x8c\'}\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试使用以下代码读取和打印文件数据:
\n\nfile = open("output.txt", "r")\ntext = file.read()\nfile.close()\nprint text\nRun Code Online (Sandbox Code Playgroud)\n\n没问题,和我在文件中看到的一模一样。但是当我尝试通过这样的索引打印字典的某些部分时:
\n\nfile = open("output.txt", "r")\ntext = file.read()\nfile.close()\nprint text[\'name\']\nRun Code Online (Sandbox Code Playgroud)\n\n一个错误说:
\n\n print text[\'name\']\nTypeError: string indices must be integers, not str\nRun Code Online (Sandbox Code Playgroud)\n\n但是当我直接运行这段代码时,我可以看到它正在工作:
\n\ntemp = {\'name\': u\'\xd8\xa7\xd8\xad\xd8\xb3\xd8\xa7\xd9\x86\', \'family\': u\'\xd8\xb4\xdb\x8c\xd8\xb1\xd8\xb2\xd8\xa7\xd8\xaf\xdb\x8c\'}\nprint temp[\'name\']\nRun Code Online (Sandbox Code Playgroud)\n\n这里有什么问题?
\n我尝试运行项目时遇到此错误.产生此错误的代码行是:
from DomainServices.models.movie import Movie
Run Code Online (Sandbox Code Playgroud)
但是我的模型文件夹和movie.py文件中有Movle类.我也有一个__init__.py包含:
__author__ = 'ehsan'
Run Code Online (Sandbox Code Playgroud)
正如我在这里读到的:Python错误"ImportError:没有命名模块"我确定问题不在于init .py内容,因为我用另一个项目中的工作替换了这个文件.整个错误是:
[root@h149-3-137-195 DomainServices]$ python DomainServices/cron/imdb_crawler.py
Traceback (most recent call last):
File "DomainServices/cron/imdb_crawler.py", line 6, in <module>
from DomainServices.models.movie import Movie
ImportError: No module named DomainServices.models.movie
Run Code Online (Sandbox Code Playgroud)
这是我的项目结构:
在项目目录中,当我运行'python'并运行该导入命令时,没有问题!我该怎么办?
我想在Debian 9中安装npm。
apt-get install nodejs
Run Code Online (Sandbox Code Playgroud)
完全安装和nodejs -v结果:v4.8.2。
但是,当尝试运行npm时,错误提示:
bash: npm: command not found
Run Code Online (Sandbox Code Playgroud)
根据搜索,我尝试了其他方法:根据此指南:https : //www.godaddy.com/help/install-nodejs-ubuntu-17395我尝试了:
sudo apt-get install npm
Run Code Online (Sandbox Code Playgroud)
结果:
E: Package 'npm' has no installation candidate
Run Code Online (Sandbox Code Playgroud)
根据我尝试过的另一指南:
wget https://npmjs.org/install.sh
sudo chmod +x install.sh
sudo ./install.sh
Run Code Online (Sandbox Code Playgroud)
结果:
npm cannot be installed without node.js.
Run Code Online (Sandbox Code Playgroud)
当然,我已经安装了nodejs。我也尝试过这种方式:
curl --silent --location https://deb.nodesource.com/setup_0.12 | sudo bash -
sudo apt-get update
sudo apt-get install --yes nodejs
Run Code Online (Sandbox Code Playgroud)
它说:
nodejs is already the newest version (4.8.2~dfsg-1).
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
我想检查我的输入的长度是否为任何类型的字符 {5,50} 。我使用了这段代码:
re.match('.{5,50}', my_string)
Run Code Online (Sandbox Code Playgroud)
问题是,当字符串超过 50 个字符时,它不会返回 None。我应该怎么办?
python ×7
android ×2
json ×2
autogrow ×1
binary-data ×1
cordova ×1
css ×1
debian ×1
dictionary ×1
file ×1
html ×1
httprequest ×1
imageview ×1
jquery ×1
large-data ×1
node.js ×1
npm ×1
npm-install ×1
obfuscation ×1
pyqt ×1
python-2.7 ×1
qt-designer ×1
regex ×1
sqlite ×1
text-files ×1
ubuntu ×1
urllib2 ×1