当passint新浮点值时应用程序崩溃

时间:2014-06-14 11:02:35

标签: android android-custom-view

  • 导致应用崩溃的原因是什么?

我有一个基于BluetoothChat示例的应用程序。我创建了新的包,在那里我持有我的视图类,如速度计。我想从BluetoothChat.java获取一个值并将其设置在Speedometer.java中 因此有onSpeedChangeListener接口

enter image description here

在BluetoothChat中添加了这个:

int i = Integer.parseInt(readMessage.replaceAll("[\\D]", ""));               
                speedValue = (float)i;                
                final Speedometer speedometer = (Speedometer) findViewById(R.id.Speedometer);
                speedometer.onSpeedChanged(speedValue);

SpeedChangeListener:

package lt.vejoprojektai.View;

public interface SpeedChangeListener {

    public void onSpeedChanged(float newSpeedValue);

}

Speedometer.java

@Override
    public void onSpeedChanged(float newSpeedValue) {
        this.setCurrentSpeed(newSpeedValue);
        this.invalidate();
    }

如果我在BluetoothChat中评论尝试传递价值应用程序的行。

logcat的:

06-14 14:00:57.100: W/dalvikvm(24290): threadid=1: thread exiting with uncaught exception (group=0x415b5b90)
06-14 14:00:57.110: E/AndroidRuntime(24290): FATAL EXCEPTION: main
06-14 14:00:57.110: E/AndroidRuntime(24290): Process: com.example.android.BluetoothChat, PID: 24290
06-14 14:00:57.110: E/AndroidRuntime(24290): java.lang.NullPointerException
06-14 14:00:57.110: E/AndroidRuntime(24290):    at com.example.android.BluetoothChat.BluetoothChat$2.handleMessage(BluetoothChat.java:299)
06-14 14:00:57.110: E/AndroidRuntime(24290):    at android.os.Handler.dispatchMessage(Handler.java:102)
06-14 14:00:57.110: E/AndroidRuntime(24290):    at android.os.Looper.loop(Looper.java:137)
06-14 14:00:57.110: E/AndroidRuntime(24290):    at android.app.ActivityThread.main(ActivityThread.java:4998)
06-14 14:00:57.110: E/AndroidRuntime(24290):    at java.lang.reflect.Method.invokeNative(Native Method)
06-14 14:00:57.110: E/AndroidRuntime(24290):    at java.lang.reflect.Method.invoke(Method.java:515)
06-14 14:00:57.110: E/AndroidRuntime(24290):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:811)
06-14 14:00:57.110: E/AndroidRuntime(24290):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:627)
06-14 14:00:57.110: E/AndroidRuntime(24290):    at dalvik.system.NativeStart.main(Native Method)

编辑 enter image description here

EDIT2

@Override
    public void onCreate(Bundle savedInstanceState) {
        final int mUIFlag = 
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                      | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                      | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                      | View.SYSTEM_UI_FLAG_LOW_PROFILE
                      | View.SYSTEM_UI_FLAG_FULLSCREEN
                      | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                      | View.SYSTEM_UI_FLAG_IMMERSIVE;
        super.onCreate(savedInstanceState);
        if(D) Log.e(TAG, "+++ ON CREATE +++");

        // Set up the window layout
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().getDecorView().setSystemUiVisibility(mUIFlag);
        setContentView(R.layout.main);

然后使用菜单中的按钮我打开新视图setContentView(R.layout.cluster);但菜单未隐藏...

1 个答案:

答案 0 :(得分:1)

错误 NullPointerException 我认为它没有找到速度计的资源,

确保速度表是否处于相同的布局,如果没有,那么你应该从它可以获得的位置充气视图布局。

我不认为在此解析浮点错误。 祝你好运