将 gradle 版本更新到 3.3 后(我不确定这是否有任何影响),但有时,我的构建需要大约 30 分钟。当构建完成或取消时,我在项目的主包中看到一个名为“java_pid1160.hprof”的文件。文件大小约为 2-5~ GB。当这种情况发生时,我的 CPU 疯狂工作,并且我看到风扇活动增加。我知道 hprof 文件是 java 内存转储,但由于 Android Studio 有内存监视器并将内存转储到 hprof 文件,因此很难找到任何有用的东西。还有其他人遇到这个问题吗?
在init方法中,findViewById在R.id.disable_view_content上返回null。
public class DisableView extends RelativeLayout {
private View content;
private View disableView;
private int disableBackgroundColor;
private boolean isEnabled;
public DisableView(Context context) {
super(context);
init();
}
public DisableView(Context context, AttributeSet attrs) {
super(context, attrs);
obtainAttributes(context, attrs);
init();
}
public DisableView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
obtainAttributes(context, attrs);
init();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public DisableView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
obtainAttributes(context, attrs);
init();
}
private void obtainAttributes(Context context, AttributeSet attributeSet) {
TypedArray …Run Code Online (Sandbox Code Playgroud) 由于我是初学者而且我不想参与布局管理器,我只是将JPanel添加到我的主JFrame中,并为面板中的每个组件提供特定位置.但不知何故输出似乎太错了..
frame = new JFrame(email + " (Offline)");
frame.setSize(400, 400);
frame.setLocation(0, 0);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.setLayout(new FlowLayout());
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
// out.println("BYE");
// out.flush();
frame.dispose();
thread.stop();
}
});
panel = new JPanel();
frame.add(panel);
chat = new JTextArea();
chat.setSize(400, 200);
chat.setLocation(0, 0);
chat.setEditable(false);
panel.add(chat);
panel.validate();
JLabel you = new JLabel("You:");
you.setSize(you.getPreferredSize());
you.setLocation(0, 210);
panel.add(you);
panel.validate();
input = new JTextArea();
input.setSize(200, 200);
input.setLocation(0, 220 + chat.getSize().height);
panel.add(input);
panel.validate();
send = new JButton("Send");
send.setSize(send.getPreferredSize());
send.setLocation(210, 220 + chat.getSize().height);
panel.add(send);
panel.validate(); …Run Code Online (Sandbox Code Playgroud) 我一直在尝试连接到服务器来检索一些数据.我想到的第一件事就是创建一个异步连接的线程.
new Thread(new Runnable() {
@Override
public void run() {
// retrieve data
}
}).run();
Run Code Online (Sandbox Code Playgroud)
但奇怪的是,我创建的线程与UI线程同步,我得到了一个网络异常,所以我最终使用了AsyncTask.你们知道什么可能导致线程与UI线程异步工作吗?我的课程延伸到一个片段.