小编Joh*_*rts的帖子

让程序运行缓慢

有没有办法通过改变Linux中的任何操作系统参数来慢慢运行C++程序?通过这种方式,我想模拟如果特定程序碰巧在真正较慢的机器上运行会发生什么.

换句话说,更快的机器应该表现为该特定程序的较慢机器.

c c++ unix linux ubuntu

102
推荐指数
4
解决办法
1万
查看次数

如何在Linux内核中睡觉?

我可以使用msleep()函数在内核空间中休眠一段指定的时间吗?如果是这样,我需要包含哪些头文件?#include <linux/time.h>似乎不是正确的.是否有更好的功能用于此目的?

c linux sleep linux-kernel

19
推荐指数
2
解决办法
4万
查看次数

"找不到持久性单元"错误

我收到以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor': Cannot create inner bean '(inner bean)' while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'txManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txManager' defined in class path resource [persistenceLayer.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jpa

18
推荐指数
1
解决办法
4万
查看次数

Android - 只读文件系统IOException

我想写一个Android系统上的简单文本文件.这是我的代码:

public void writeClassName() throws IOException{
    String FILENAME = "classNames";
    EditText editText = (EditText) findViewById(R.id.className);
    String className = editText.getText().toString();

    File logFile = new File("classNames.txt");
       if (!logFile.exists())
       {
          try
          {
             logFile.createNewFile();
          } 
          catch (IOException e)
          {
             // TODO Auto-generated catch block
             e.printStackTrace();
          }
       }
       try
       {
          //BufferedWriter for performance, true to set append to file flag
          BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); 
          buf.append(className);
          buf.newLine();
          buf.close();
       }
       catch (IOException e)
       {
          // TODO Auto-generated catch block
          e.printStackTrace();
       }
Run Code Online (Sandbox Code Playgroud)

但是,此代码生成"java.io.IOException:open failed:EROFS(只读文件系统)"错误.我尝试将权限添加到我的Manifest文件,如下所示,但没有成功:

<?xml …
Run Code Online (Sandbox Code Playgroud)

java android android-emulator

18
推荐指数
1
解决办法
5万
查看次数

ListActivity TwoLineListItem替代方案

我注意到,从API 17开始,不推荐使用TwoLineListItem.如果我按如下方式设置ListActivity适配器,有什么替代方案?:

ArrayAdapter<File> adapter = new ArrayAdapter<File>(this,android.R.layout.simple_list_item_2,filesArrayList){
            @Override
            public View getView(int position, View convertView, ViewGroup parent){
                final TwoLineListItem row;
                if(convertView == null){
                    LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    row = (TwoLineListItem)inflater.inflate(android.R.layout.simple_list_item_2, null);
                }else{
                    row = (TwoLineListItem)convertView;
                }
                row.getText1().setText(filesArrayList.get(position).getTitle());
                row.getText2().setText2(filesArrayList.get(position).getDescription());
                return row;
            }

        };
Run Code Online (Sandbox Code Playgroud)

java android listactivity

14
推荐指数
2
解决办法
7051
查看次数

Android:实现ViewHolder

我试图在我的Android应用程序中实现ViewHolder,但我一直认为ViewHolder无法解析为某种类型,没有任何导入建议.有谁知道怎么解决这个问题?

java android

14
推荐指数
1
解决办法
2万
查看次数

BroadcastReceiver没有收到下载完成动作

我试图捕获下载完成事件,但我的BroadcastReceiver没有收到它们.这是接收器:

public class DownloadListenerService extends BroadcastReceiver {        
    @Override
    public void onReceive(final Context context, Intent intent) {
        System.out.println("got here");
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = settings.edit();

        String action = intent.getAction();
        if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
            String downloadPath = intent.getStringExtra(DownloadManager.COLUMN_URI);
            editor.putString("downloadPath", downloadPath);
            editor.commit();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是清单:

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

    <receiver 
        android:name="com.example.alreadydownloaded.DownloadListenerService" 
        android:exported="true">
        <intent-filter>
            <action android:enabled="true" android:name="android.intent.action.DOWNLOAD_COMPLETE" />
        </intent-filter>
    </receiver>
 </application>
Run Code Online (Sandbox Code Playgroud)

有谁看到了什么问题?

java android broadcastreceiver

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

算术C++运算符

我在技术访谈中刚问了一个问题,我有点困惑.

问题如下:

如果

int i = -1, int j = -1, and int k = -1, 
Run Code Online (Sandbox Code Playgroud)

我们运行以下行:

++i && ++j && ++k
Run Code Online (Sandbox Code Playgroud)

i,j和k的新值是什么?我感到困惑的原因是,因为我们没有将这个表达式赋值给任何东西,所以看起来并不像运算符应该有任何区别(只有增量运算符应该).然而,运行一个简单的测试程序很快证明我错了.有人可以向我解释这个,因为我之前从未见过这个练习.

c++ arithmetic-expressions

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

利用亚微秒精度测量Linux内核空间的时间

我目前正在使用该do_gettimeofday()函数来测量内核中的时间,这给了我微秒的精度.有没有比这更精确的东西(可能是纳秒级)?

c linux time linux-kernel

10
推荐指数
2
解决办法
9271
查看次数

Google Drive未解决的进口广告

我正在尝试编译Stephen Wylie的Google Drive集成示例代码:

package com.googledrive.googledriveapp;
// For Google Drive / Play Services
// Version 1.1 - Added new comments & removed dead code
// Stephen Wylie - 10/20/2012
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;

import com.google.android.gms.auth.GoogleAuthException;
import com.google.android.gms.auth.GoogleAuthUtil;
import com.google.android.gms.auth.UserRecoverableAuthException;
import com.google.android.gms.common.AccountPicker;
import com.google.api.client.auth.oauth2.BearerToken;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.android2.AndroidHttp;
import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.json.JsonHttpRequest;
import com.google.api.client.http.json.JsonHttpRequestInitializer;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.Drive.Files;
import com.google.api.services.drive.DriveRequest;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.File;
import com.google.api.services.drive.model.FileList;

public class MainActivity extends Activity {

    private Button …
Run Code Online (Sandbox Code Playgroud)

java android google-drive-api

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