问题是,无论我在何处或如何调用此布局的组件,它们始终返回null.
setView(inflater.inflate(R.layout.search_layout, null))
Run Code Online (Sandbox Code Playgroud)
这很好用.它显示了里面的布局Dialog
,但是,子节点总是返回为null findViewById(R.id.some_search_layout_children)
.
我试图清理我的项目多次,试图实现另一个类我Dialog
,叫findViewById()
我的主要成员Activity
,内部initSearch()
方法,以及一个匿名实现内部OnClickListener
的Dialog
,但都具有相同的结果.我还尝试将孩子们分成独立的View
s并以编程方式调用它们:
TextView text = (TextView) findResourceById(R.id.new_independant_textview);
Run Code Online (Sandbox Code Playgroud)
但是,同样的结果.
这是相关代码:
public class Xyz extends Activity {
public void onCreate(...) { // some listener will trigger initSearch() }
private void initSearch() {
AlertDialog.Builder searchDialog = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
searchDialog.setTitle("Search Photos");
searchDialog.setMessage("Specify tag and value...");
// R.layout.search_dialog is my custom layour, it displays fine, it works.
searchDialog.setView(inflater.inflate(R.layout.search_dialog, null));
EditText …
Run Code Online (Sandbox Code Playgroud) android nullpointerexception android-dialog findviewbyid android-resources
我的第一个问题:
我一直试图解决这个问题几天,但我已经到了失去耐心的地步.以下是一些代码和我的项目结构.
问题:如何getResources()
在eclipse中和导入jar后工作?
谢谢您的帮助.
public enum Icons {
XXX("src/resoruces/icons/xyz.png");
private ImageIcon icon;
Icons(String path) {
try {
// will fail miserably in eclipse and after exporting to jar
URL imageURL = getClass().getClassLoader().getResource(path);
icon = new ImageIcon(imageURL);
} catch (Exception e) {
// works like a char in eclipse and after creating the jar file
// with the files in the same directory
System.out.println("getResoruce() did not work");
icon = new ImageIcon(path);
}
}
Run Code Online (Sandbox Code Playgroud)
当我的窗口发生变化时,我正在努力调整缓冲区的大小。除了这一部分之外,该过程的每个部分都按预期工作。
// in MyGame.h -
private:
ComPtr<ID3D11RenderTargetView> gRenderTarget;
...
// handle resize method:
void MyGame::UpdateBackbufferSize(UINT pWidth, UINT pHeight) {
/* 1. Clear render targets from device context */
gDeviceContext->OMSetRenderTargets(0, 0, 0);
/* 2. Release Rendering Target */
gRenderTarget->Release(); // ! CANNOT ACCESS client.h private Release()
/* 3. Resize buffer */
gSwapchain->ResizeBuffers(
0,
pWidth,
pHeight,
DXGI_FORMAT_UNKNOWN,
0
);
/* 4. Reset the buffer as target view */
ComPtr<ID3D11Texture2D> backBuffer;
gSwapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), &backBuffer);
gDevice->CreateRenderTargetView(backBuffer.Get(), nullptr, &gRenderTarget);
backBuffer.Get()->Release();
/* 5. Set the new …
Run Code Online (Sandbox Code Playgroud)