我已经为onClick另一个视图的自定义对话框顶部编写了代码.它给了我nullpointer exception.我也尝试过使用Layout inflater.它给了我错误ok.setOnclickListener.我的代码有什么问题?
ImageButton search =(ImageButton) findViewById(R.id.search);
search.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog searchDialog = new Dialog(Page.this);
/*LayoutInflater inflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.search, null);
searchDialog.addContentView(layout, new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
searchDialog.setContentView(layout);*/
searchDialog.setContentView(R.layout.search);
searchDialog.setTitle("Search Dialog");
searchDialog.setCancelable(true);
Button ok = (Button)findViewById(R.id.OkButton);
ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String searchString = null;
EditText searchText = (EditText)findViewById(R.id.searchText);
if(searchText.getText()!=null){
searchString = searchText.getText().toString();
}
Log.i("TAG","Search word :"+searchString);
}
});
searchDialog.show(); …Run Code Online (Sandbox Code Playgroud) 我正在运行一些Windows应用程序,它工作了几天然后停止工作没有错误.现在我在事件查看器中发现了这个错误.也许有人知道什么会导致这个错误?
事件类型:错误
事件源:.NET Runtime 2.0错误报告事件
类别:无
事件ID:5000
日期:2010年10月30日
时间:21:58:57
用户:N/A.
电脑:SERVER-PROD
描述:EventType clr20r3,P1 program.exe,P2 1.0.0.0,P3 4cca7ed1,P4 mscorlib,P5 2.0.0.0,P6 4be90358,P7 1164,P8 0,P9 system.objectdisposedexception,P10 NIL.
也许这是一个愚蠢的问题.每次我做一个@property我必须这样@synthesize做.但这没有任何意义,你可以做的唯一事情@property(whatever) Type* property就是@synthesize property在实现文件中做.为什么两者都需要?为什么编译器在没有必须编写的情况下自动生成getter/setter方法@synthesize property.
我写了以下课程:
class myClass(object):
def __init__(self):
pass
def foo(self, arg1, arg2):
pp = foobar(self, arg1, arg2)
if pp:
return 42
else
return -666
def foobar(self, arg1, arg2):
if arg1 == arg2:
return 42
else:
return None
Run Code Online (Sandbox Code Playgroud)
逻辑是荒谬的 - 忽略它.我想要的是从另一个实例方法调用实例方法 - 我得到了一个NameError.我原本以为这是因为它在定义之前foo()调用foobar()了 - 但是在脚本中切换函数定义的顺序没有任何区别.
是否有人导致此错误,以及如何解决它?
我正在使用此代码段来加载各种图像文件:
BitmapImage bitmap = new BitmapImage ();
bitmap.BeginInit ();
bitmap.UriSource = new System.Uri (path);
bitmap.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
bitmap.EndInit ();
Run Code Online (Sandbox Code Playgroud)
这适用于存储为RGB,RGB + Alpha和CMYK的TIFF文件.但是,如果我尝试使用CMYK颜色和Alpha通道加载TIFF文件,则会出现异常(解码器无法识别文件格式有效).
我之前使用过FreeImage库和一个很薄的C#包装器.FreeImage 3.x对这种图像格式有部分支持,即我必须加载TIFF两次,一次是CMYK,没有透明度,一次是RGB + Alpha; 因为FreeImage只能访问最多4个同时颜色通道,所以需要这个技巧.
我想知道是否有一种加载CMYK + Alpha位图的支持方式?直接在C#中或通过一些互操作代码,但最好不必使用第三方DLL(除了.NET 4框架库).
可在此处找到此类TIFF文件的示例.
编辑:我不能再重现问题,以下代码工作得很好:
BitmapImage bitmap = new BitmapImage ();
bitmap.BeginInit ();
bitmap.UriSource = new System.Uri (path);
bitmap.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
bitmap.EndInit ();
byte[] pixels = new byte[bitmap.PixelHeight*bitmap.PixelWidth*5];
bitmap.CopyPixels (pixels, bitmap.PixelWidth * 5, 0);
Run Code Online (Sandbox Code Playgroud)
但我仍然陷入困境:如何才能发现源图像被编码为CMYK加Alpha通道?查看Format属性时,我只获得图像每像素40位的信息.所有有趣的东西都存储在以下非公共属性中:
bitmap.Format.FormatFlags == IsCMYK | NChannelAlpha;
bitmap.Format.HasAlpha == true;
Run Code Online (Sandbox Code Playgroud)
有没有任何正式的方式来接触他们,而不诉诸反思?
我无法从文件中读取数据,并将数据(文本)的选定部分连接到我自己的缓冲区中.
代码如下:
char buffer[1000];
char* allNewData = (char *)malloc(10000);
while (! myfile.eof() )
{
myfile.getline (buffer, 1000);
pch = strstr (buffer,"bla bla");
if(pch == NULL)
{
char* temp = buffer;
strcat(allNewData, temp);
strcat(allNewData, "\n");
}
else
{
strcat(allNewData, "here's bla bla");
strcat(allNewData, "\n");
}
}
cout<<allNewData<<endl;
Run Code Online (Sandbox Code Playgroud)
当我运行程序时,allNewData首先有一些垃圾文本,然后是正确/预期的结果,如下所示:
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii <-rubbish data
hello <- actual data
Run Code Online (Sandbox Code Playgroud)
我需要摆脱这些垃圾数据,如何更改代码来实现这一目标?
我想检查在文本字段中输入的字段是否是电子邮件.如果其电子邮件字段然后继续显示一些警告或错误.我不知道如何验证该字段.请帮帮我
我在IIS6 Web服务器后面提供Django应用程序.
测试服务器运行完美,但是当在Web服务器后面运行模块导致导入时我收到此错误:
加载pyodbc模块时出错:DLL加载失败:找不到指定的模块
只是为了记录该模块是pyodbc
该网站使用isapi-wsgi通过isapi提供
有任何想法吗?这真的会让我的一天!:)