小编Tom*_*eck的帖子

将字符串分解为子字符串,Android

我正在创建一个程序,让用户输入一个句子,然后,应用程序会将String分解为子字符串,其中空格是打破原始字符串的原因.

import java.util.StringTokenizer;


    public class whitespace {

    public static void main(String[] args) {

    String text = "supervisors signature tom hanks";
    int tokenCount; //number of words
    int idx=0; // index
    String words[]=new String [500]; // space for words


     StringTokenizer st=new StringTokenizer(text); // split text into segements
     tokenCount=st.countTokens(); 
     while (st.hasMoreTokens()) // is there stuff to get?
     {
         words[idx]=st.nextToken();
         idx++;
     }
}
Run Code Online (Sandbox Code Playgroud)

到目前为止我有这个代码,虽然它作为常规Java程序工作正常,但while循环似乎导致应用程序进入无限循环.有任何想法吗?

java string android stringtokenizer

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

安装usblib包 - Ubuntu

我需要包libusb用于我正在安装的另一个包.

我尝试了以下似乎安装包,

sudo apt-get install libusb-dev
Run Code Online (Sandbox Code Playgroud)

但是当我尝试安装我得到的其他包时,

configure: error: Package requirements (libusb-1.0 >= 0.9.1) were not met:

No package 'libusb-1.0' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBUSB_CFLAGS
and LIBUSB_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
Run Code Online (Sandbox Code Playgroud)

当我运行命令dpkg -L libusb-dev时,我得到:

/.
/usr
/usr/bin
/usr/bin/libusb-config
/usr/include
/usr/include/usb.h
/usr/lib
/usr/lib/libusb.a
/usr/lib/libusb.la
/usr/lib/pkgconfig
/usr/lib/pkgconfig/libusb.pc
/usr/share
/usr/share/doc
/usr/share/doc/libusb-dev
/usr/share/doc/libusb-dev/html
/usr/share/doc/libusb-dev/html/index.html
/usr/share/doc/libusb-dev/html/preface.html …
Run Code Online (Sandbox Code Playgroud)

linux ubuntu pkg-config libusb package

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

最理想的方法是在类中保存密码 - Java

我有两个类"User Profile"和"FingerprintProfile",它们扩展了一个抽象类"Profile".

轮廓:

/**
 * Template for User profiles or Fingerprint profiles
 */
public abstract class Profile {

    /**
     * Profile Name
     */
    private String name;

    /**
     * Profile id
     */
    private int id;

    /**
     * Set the name of this profile
     * @param name
     */
    public void setProfileName(String name) {
        this.name = name;
    }

    /**
     * Set the id of this profile
     * @param name
     */
    public void setIdNumber(int id) {
        this.id = id;
    }

    /**
     * Get the …
Run Code Online (Sandbox Code Playgroud)

java passwords abstract-class design-patterns password-protection

2
推荐指数
3
解决办法
3161
查看次数

编译器找不到所需的SSL库-未定义的引用

我正在尝试编译依赖于某些SSL库的C程序。当我尝试编译时,出现以下错误:

michael@michael-VirtualBox:~/$ cc -lssl -lcrypto iot.o tun2iot.o -o tun2iot
iot.o: In function `_iot_wfd_new':
iot.c:(.text+0x21b): undefined reference to `CRYPTO_malloc'
iot.o: In function `_iot_wfd_free':
iot.c:(.text+0x289): undefined reference to `CRYPTO_free'
iot.c:(.text+0x29d): undefined reference to `CRYPTO_free'
iot.o: In function `_iot_frame_ind':
iot.c:(.text+0x366): undefined reference to `CRYPTO_free'
iot.o: In function `_iot_error_ind':
iot.c:(.text+0x3f4): undefined reference to `CRYPTO_free'
iot.o: In function `_iot_do_phase_connect':
iot.c:(.text+0xb95): undefined reference to `SSL_connect'
iot.c:(.text+0xbad): undefined reference to `SSL_get_error'
iot.o: In function `_iot_frame_recv':
iot.c:(.text+0xfe6): undefined reference to `CRYPTO_free'
iot.c:(.text+0x1377): undefined reference to `CRYPTO_free'
iot.o: In …
Run Code Online (Sandbox Code Playgroud)

c ssl linker undefined-reference ubuntu-12.04

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

将if-elseif语句转换为字典

我有以下代码用于对服务器进行RESTful调用:

def request(self, request, account_id, user):

    if request is 'get_id':
        #Get user from id
        result = requests.get(api_root + "/accounts/" + account_id + "/users/" + user, headers=self.headers)

    elif request is 'get_username':
        #Get user from username
        result = requests.get(api_root + "/accounts/" + account_id + "/users?username=" + user, headers=self.headers)

    elif request is 'get_email':
        #Get user from username
        result = requests.get(api_root + "/accounts/" + account_id + "/users?email=" + user, headers=self.headers)

    elif request is 'post':
        #Add user to new account
        result = requests.post(api_root + '/accounts/' …
Run Code Online (Sandbox Code Playgroud)

python dictionary design-patterns switch-statement

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

将具体实现作为通用返回

我有一个看起来像这样的界面:

public interface IFaker
{
    Faker<T> GetFaker<T>() where T : class;
}

public class DogFaker : IFaker
{
    public Faker<T> GetFaker<T>() where T : class
    {
        return new Faker<Dog>()
            .RuleFor(dog => dog.Name, f => f.Name.FirstName(Name.Gender.Male))
            .RuleFor(dog => dog.IsGoodBoy, f => f.Random.Bool());
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是 - 我不能Faker<Dog>代替Faker<T>例如

Bogus.Faker<_scratchpad.models.Dog>' to 'Bogus.Faker<T>

显然我无法改变new Faker<Dog>,new Faker<T>因为那时我无法访问Dog属性.

我想像这样使用对象:

private Dictionary<string, object> _fakers;

public FakerService()
{
    _fakers = InitialiseFakers();
}

private Dictionary<string, object> InitialiseFakers()
{
   return new Dictionary<string, …
Run Code Online (Sandbox Code Playgroud)

c# oop generics generic-programming bogus

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

空指针异常EditText - Android

我试图提示用户有一个对话框,其中包含两个EditText框,一个正面和负面的按钮.当我尝试从EditText框中检索值时,我得到的问题是一个空指针异常.这是我的代码,

            LinearLayout layout = new LinearLayout(context);
            layout.setOrientation(LinearLayout.VERTICAL);

            LayoutInflater inflater = LayoutInflater.from(context);
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle("New Location");
            builder.setView(inflater.inflate(R.layout.new_location_dialog, null)); 

            final EditText titleBox = (EditText)findViewById(R.id.title);
            final EditText descriptionBox = (EditText)findViewById(R.id.description);             

            builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int button) {

                    String title = titleBox.getText().toString();
                    String description = descriptionBox.getText().toString();
                    Log.d("User Setting title / description to: ", title + " : " + description);

                    //Add new Point to Map
                    addGeoPointToMap(mapOverlays,longpressLocation,title, description);    

                    return;
                }
            });

            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface …
Run Code Online (Sandbox Code Playgroud)

android dialog nullpointerexception android-edittext

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

正确使用Singleton Pattern

我试图实现单例模式的一个例子.我们的一个问题是运行两个线程,每个线程调用getInstance()并验证只创建了一个Singleton对象的实例.

这是我的Singleton代码;

public class OurSingleton {

    static OurSingleton ourSingleton;
    static int instanceCounter;

    private OurSingleton(){
        instanceCounter++;
    }

    public static synchronized OurSingleton GetSingletonInstance(){

        if( ourSingleton == null){

            ourSingleton = new OurSingleton();

        }
        return ourSingleton;    
    }

    public static int getCounter() {

        return instanceCounter;

    }
}
Run Code Online (Sandbox Code Playgroud)

而我的主要;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {

        OurSingleton mySingleton = null;

        Thread one = new Thread(new GetSingletonInstance(mySingleton));
        Thread two = new Thread(new GetSingletonInstance(mySingleton));

        one.start();
        two.start();


        System.out.println("Main: " + mySingleton.getCounter()); …
Run Code Online (Sandbox Code Playgroud)

java singleton multithreading synchronization design-patterns

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

ClassNotFoundException:以前在使用Android Project

我有一个有效的Android项目,但需要从头开始.我复制了所有源文件和布局文件.没有编译错误但是当我尝试运行时,我收到以下错误.

11-27 17:21:56.793: E/AndroidRuntime(1450): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{projects.mobile.mapappproject/projects.mobile.mapappproject.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "projects.mobile.mapappproject.MainActivity" on path: /data/app/projects.mobile.mapappproject-1.apk
Run Code Online (Sandbox Code Playgroud)

我正在运行eclipse juno并尝试在Android 4.2上运行.谢谢 !

java eclipse android android-4.2-jelly-bean

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

当应用程序在前台时未触发 onMessageReceived

我正在按照教程在我的 android 设备上接收推送通知。

我可以从 Firebase 控制台发送推送通知 - 我也可以在 logcat 中看到 Firebase 事件,但我onMessageReceived的从未被解雇。我的应用程序在前台运行。

这是我发送通知后 logcat 中的输出:

12-31 12:23:54.741 9453-11132/com.example.app D/FA: Logging event (FE): notification_receive(_nr), Bundle[{firebase_event_origin(_o)=fcm, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=407943440756026938, message_device_time(_ndt)=0, message_name(_nmn)=Label Arse, message_time(_nmt)=1514723034, message_id(_nmid)=3115372290763926350}]
12-31 12:23:54.784 9453-11132/com.example.app V/FA: Connecting to remote service
12-31 12:23:54.797 9453-11132/com.example.app D/FA: Logging event (FE): notification_foreground(_nf), Bundle[{firebase_event_origin(_o)=fcm, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=407943440756026938, message_device_time(_ndt)=0, message_name(_nmn)=Label Arse, message_time(_nmt)=1514723034, message_id(_nmid)=3115372290763926350}]
12-31 12:23:54.828 9453-11132/com.example.app V/FA: Connection attempt already in progress
12-31 12:23:54.829 9453-11132/com.example.app D/FA: Connected to remote service
12-31 12:23:54.829 9453-11132/com.example.app V/FA: …
Run Code Online (Sandbox Code Playgroud)

android push-notification firebase firebase-cloud-messaging

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