小编Tah*_*lil的帖子

关于静态关键字的困惑

我刚刚在一个文档中读到"静态方法只能调用其他静态方法而不能从中调用非静态方法".但是当我试图测试它时,我认为看到了不同的东西.

我有一个C级,如下所述

import pckage1.*;

public class C
{

public static void main(String par[])
{       
}
public static void cc() 
{
    A ob = new A();
    ob.accessA(0);      
}   

}
Run Code Online (Sandbox Code Playgroud)

A级是哪里

package pckage1;

public class A 
{
public A() 
{
}
public void accessA(int x)
{   
}

}
Run Code Online (Sandbox Code Playgroud)

现在来自C类中的cc STATIC方法,调用NON STATIC方法accessA().如果关于静态方法的陈述是真的,怎么可能呢?

java oop static

1
推荐指数
1
解决办法
176
查看次数

在线性布局中添加按钮会崩溃

我真的不明白为什么这个简单的代码在这一行崩溃了 layout.addView(button);

super.onCreate(savedInstanceState);
    layout = (LinearLayout)findViewById(R.id.linearLayout);
    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

    Button button = new Button(this);
    button.setHeight(100);
    button.setWidth(100);
    button.setText("HELLO");
    button.setLayoutParams(p);
    layout.addView(button);
Run Code Online (Sandbox Code Playgroud)

activity_main.xml中

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayout">
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

编辑:编辑过的代码仍然粉碎.但现在压缩setContentView.

super.onCreate(savedInstanceState);

    layout = (LinearLayout)findViewById(R.id.linearLayout);
    setContentView(layout); 
    LayoutParams p = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);

    int i,j;
    Button button = new Button(this);
    button.setHeight(100);
    button.setWidth(100);
    button.setText("HELLO");
    layout.addView(button,p);
Run Code Online (Sandbox Code Playgroud)

Logcat报告 在此输入图像描述

android android-linearlayout

0
推荐指数
1
解决办法
365
查看次数

QObject:connect没有这样的插槽问题

我不知道为什么会发生这种情况.我已经扩展QObject并添加了宏Q_OBJECT.信号和插槽也有相同的参数.

我已经发布了原始问题

http://supportforums.blackberry.com/t5/Cascades-Development/Object-connect-No-such-slot-problem/mp/2486753

这是我的hpp文件:

/*
 * LocationMonitor.hpp
 *
 *  Created on: Jul 13, 2013
 *      Author: Roland
 */

#ifndef LOCATIONMONITOR_HPP_
#define LOCATIONMONITOR_HPP_

#include <QObject>
#include <QtLocationSubset/qgeopositioninfo.h>
#include <QtLocationSubset/qgeoareamonitor.h>

using namespace Qt;
using namespace QtMobilitySubset;
class GeoNotification;
class LocationMonitor : public QObject
{
    Q_OBJECT
public:
    LocationMonitor(int id,GeoNotification *geoNotification,QVariantList locationList,QVariantList actionList);
    virtual ~LocationMonitor();

public slots:
    void areaEnteredd(QtMobilitySubset::QGeoPositionInfo info);
    void areaExitedd(QtMobilitySubset::QGeoPositionInfo info);

public:
    QGeoAreaMonitor *monitor;
};

#endif /* LOCATIONMONITOR_HPP_ */
Run Code Online (Sandbox Code Playgroud)

这是我的cpp文件

/*
 * LocationMonitor.cpp
 *
 *  Created on: Jul …
Run Code Online (Sandbox Code Playgroud)

c++ qt signals-slots blackberry-10

0
推荐指数
1
解决办法
7399
查看次数

在头文件中将函数声明为静态会导致声明但未定义的错误

假设我有一个像这样的头文件

namespace a
{
    static void fun();
}
Run Code Online (Sandbox Code Playgroud)

我在源文件中有它的定义

namespace a
{
    void fun()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

此头文件可以在这些文件的自己的项目中或在其他几个项目中使用.我得到了声明的fun()函数,但没有定义错误.我不明白为什么.但是,如果我从声明中删除静态,它就可以了!

c++ static

0
推荐指数
1
解决办法
490
查看次数

GetCurrentThreadId返回不同的threadId

我称之为提到的Windows API.但它返回的是与返回的id不同的线程ID _beginthreadex.我的代码如下,

ThreadTest *_threadTest = new ThreadTest();
Thread *_thread = new Thread(StartRoutineForThread,_threadTest);
Run Code Online (Sandbox Code Playgroud)

Thread类的构造函数是,

ThreadWin::ThreadWin(void * (*_startRoutine)(void *), void * _argument, bool _isJoinable)
{
        unsigned int _threadAddress;
        unsigned int threadID = _beginthreadex(
                                    NULL,
                                    0,
                                    (unsigned int (__stdcall *)(void *))_startRoutine,
                                    _argument,
                                    0,
                                    &_threadAddress
                                );
}
Run Code Online (Sandbox Code Playgroud)

StartRoutineForThread 作为线程的启动例程的函数如下,

void* StartRoutineForThread(void* _argument)
{
    ThreadTest *_threadTest = (ThreadTest*)_argument;
    _threadTest->Run();
    return NULL;
}
void ThreadTest::Run()
{
    this->threadID = ::GetCurrentThreadId();    
}
Run Code Online (Sandbox Code Playgroud)

现在在类的构造函数中Thread,变量threadID的值不同于我从函数得到的类ThreadTest变量threadIDRun值.但是这个Run函数是从我创建线程时指定的函数调用的.所以该Run …

c++ winapi multithreading

0
推荐指数
1
解决办法
2897
查看次数