小编ste*_*edc的帖子

字节到字符串android

所以我使用文件来保存我的程序的一些分数,但问题是我不能只打印它们.我尝试了几件事但我找不到合适的东西是我的代码:

try{
        String FILENAME = "FrogScoreFile";
        FileInputStream fos = openFileInput(FILENAME);
        byte[] b = new byte[1];
        fos.read(b);
        fos.close();
        String score= String b;
        game5HighScore.setText(b);
        }catch (java.io.FileNotFoundException e) {
        } catch (IOException e) {
                e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

string android byte

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

启动时PreferenceManager.getDefaultSharedPreferences的NullPointerException

因此,我正在重新制作几个月前的应用程序(将故障排除在外,并使一些事情变得更好)但是现在我遇到了一个问题,我没有找到,也不知道它是什么.如果我在手机上运行应用程序,则会出现此错误

01-20 22:37:46.595: E/AndroidRuntime(7350): FATAL EXCEPTION: main
01-20 22:37:46.595: E/AndroidRuntime(7350): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.stevedc.thinklogic/com.stevedc.thinklogic.TowerHanoi}: java.lang.NullPointerException
01-20 22:37:46.595: E/AndroidRuntime(7350):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
01-20 22:37:46.595: E/AndroidRuntime(7350):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-20 22:37:46.595: E/AndroidRuntime(7350):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-20 22:37:46.595: E/AndroidRuntime(7350):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-20 22:37:46.595: E/AndroidRuntime(7350):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 22:37:46.595: E/AndroidRuntime(7350):     at android.os.Looper.loop(Looper.java:137)
01-20 22:37:46.595: E/AndroidRuntime(7350):     at android.app.ActivityThread.main(ActivityThread.java:4441)
01-20 22:37:46.595: E/AndroidRuntime(7350):     at java.lang.reflect.Method.invokeNative(Native Method)
01-20 22:37:46.595: E/AndroidRuntime(7350):     at java.lang.reflect.Method.invoke(Method.java:511)
01-20 22:37:46.595: E/AndroidRuntime(7350):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-20 22:37:46.595: E/AndroidRuntime(7350):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-20 22:37:46.595: E/AndroidRuntime(7350):     at dalvik.system.NativeStart.main(Native Method)
01-20 …
Run Code Online (Sandbox Code Playgroud)

android nullpointerexception sharedpreferences

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

在Android应用程序中等待

所以我在我的android程序中使用一个等待一秒钟或更长时间的线程,但有时它会怀疑它,有时候它根本不会等待,所以是否有另一种方法可以等待几秒钟?

Thread logotimer = new Thread(){
    public void run(){
        try{
            sleep(1500);
            Intent leveloverview = new Intent("com.technopolisapp.FROGLEVEL");
            startActivity(leveloverview);
        }
        catch(InterruptedException e){
            e.printStackTrace();
        }
        finally{
            finish();
        }
    }
};

logotimer.start();
Run Code Online (Sandbox Code Playgroud)

multithreading android wait

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

Hibernate映射找不到资源

我正在尝试编译我的项目,但编译器一直给出错误,他无法找到我的资源文件,所以他无法编译

    jul 23, 2013 1:29:24 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: src/main/resources/Movies.hbm.xml
Initial SessionFactory creation failed.org.hibernate.MappingNotFoundException: resource: src/main/resources/Movies.hbm.xml not found
Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.hp.videotheek.HibernateUtil.<clinit>(HibernateUtil.java:17)
    at com.hp.videotheek.App.main(App.java:12)
Caused by: org.hibernate.MappingNotFoundException: resource: src/main/resources/Movies.hbm.xml not found
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:738)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2167)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2139)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2119)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2072)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1987)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1966)
    at com.hp.videotheek.HibernateUtil.<clinit>(HibernateUtil.java:13)
    ... 1 more
Run Code Online (Sandbox Code Playgroud)

hibernate.cfg.xml文件,在这里他找不到映射资源,但它位于正确的位置

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.url">jdbc:postgresql://localhost:5432/postgres</property>
        <property name="connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.username">postgres</property> …
Run Code Online (Sandbox Code Playgroud)

eclipse mapping hibernate maven

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

如何设置按钮不可见android

所以我试图让 A 按钮不可见,我首先在论坛上搜索了答案并尝试了它,但它不起作用。

int level=0;
    try{
        String FILENAME = "TowerFile";
        FileInputStream fos = openFileInput(FILENAME);
        byte[] b = new byte[1];
        fos.read(b);
        fos.close();
        if(new String(b).equalsIgnoreCase("1")){
            level=1;
        }
        if(new String(b).equalsIgnoreCase("2")){
            level=2;
        }
        if(new String(b).equalsIgnoreCase("3")){
            level=3;
        }
        if(new String(b).equalsIgnoreCase("4")){
            level=4;
        }
        if(new String(b).equalsIgnoreCase("5")){
            level=5;
        }
    }catch (java.io.FileNotFoundException e) {
    } catch (IOException e) {
            e.printStackTrace();
    }

    Button button1 = (Button) findViewById(R.id.button1);
    Button button2 = (Button) findViewById(R.id.button2);
    Button button3 = (Button) findViewById(R.id.button3);
    Button button4 = (Button) findViewById(R.id.button4);
    Button button5 = (Button) findViewById(R.id.button5);



    if(level==1){
        button1.setVisibility(View.INVISIBLE);
    } …
Run Code Online (Sandbox Code Playgroud)

android invisible button

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

Java文件mkdir给出错误的结果

所以我试图制作一个地图来存储一些在dir程序开头制作的文件.但是在Windows上仍然存在问题,因为目录永远不会发生.我找不到解决方案.相同的代码在Unix系统上运行良好,但在Windows系统上运行不正常.

protected String createScreenshotMap(){
        this.dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        this.date = new Date();
        String testMap = this.checkOS();
        File fileMap = null;
        boolean check;
        try{
            if(os.indexOf("win") >= 0){
                fileMap = new File(testMap);
                check = fileMap.canWrite();
                System.out.println(check);
                String path = "C:" + File.separator + "testRun" + 
                                     File.separator + this.date.toString();
                fileMap = new File(path);
                System.out.println(fileMap.getAbsolutePath());
            }else{
                fileMap = new File(testMap + this.date.toString() + "/");
            }
            check = fileMap.mkdir();
            System.out.println(check);
        }catch (Exception e){
            e.printStackTrace();
        }
        return testMap;
    }
Run Code Online (Sandbox Code Playgroud)

如果我运行这段代码,我得到以下输出

true
C:\testRun\Fri Apr …
Run Code Online (Sandbox Code Playgroud)

java windows file

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