开发者

Using GPS Value in View

开发者 https://www.devze.com 2023-03-27 10:15 出处:网络
I\'m having an issue taking a max speed value (recorded via GPS) from my application and using that value for my analog gauge view output.When running I receive a FC \"unable to expand the view\".I ca

I'm having an issue taking a max speed value (recorded via GPS) from my application and using that value for my analog gauge view output. When running I receive a FC "unable to expand the view". I can enter a static value without any issue. I am attempting to pull the max speed value (mHighestSpeedNumber) from another view (GraphCanvas.java) used for a graph which works fine. In (Analogspeed.java) where I would like to place the value, I import my variable and place the following code which no syntax errors:

private float speedvalue = (float) Double.parseDouble(mHighestSpeedNumber.toString());
private float handTarget = speedvalue;

Upon doing this I then get the force close when calling the activity.

Any help would be appreciated. I have tried many scenarios and searched with no solution yet.

I believe part of the issue may be converting a double value to a float which it needs to be. Please let me know if any other information is needed.

Thanks

GraphCanvas.java

mHighestSpeedNumber = mUnits.conversionFromMetersPerSecond( calc.getMaxSpeed() );

Analogspeed.java

package com.datamonkey.android.test;

import java.text.DecimalFormat;
import java.text.NumberFormat;

import com.datamonkey.android.test.actions.utils.GraphCanvas;
import com.datamonkey.android.test.actions.utils.StatisticsCalulator;
import com.datamonkey.android.test.actions.Statistics;
import com.datamonkey.android.test.util.UnitsI18n;

import android.view.View;

public final class AnalogSpeed extends View {

private static final String TAG = AnalogSpeed.class.getSimpleName();

private GraphCanvas mHighestSpeedNumber;

// scale configuration
private static final int totalNicks = 65;
// number values for gauge
private static final float degreesPerNick = 270.0f / totalNicks;    
private static final int centerDegree = 0; // the one in the top center (12 o'clock)
private static final int minDegrees = 0;
private static final int maxDegrees = 200;

// hand d开发者_StackOverflow中文版ynamics -- all are angular expressed in F degrees
private boolean handInitialized = false;

// Starting Position of hand
private float handPosition = centerDegree;


private float speedvalue = (float) Double.parseDouble(mHighestSpeedNumber.toString());

private float handTarget = speedvalue;

Logcat

08-09 21:52:29.511: INFO/ActivityManager(60): Starting activity: Intent { dat=content://com.datamonkey.android.test/tracks/1 cmp=com.datamonkey.android.test/.actions.Statistics }
08-09 21:52:29.719: DEBUG/AndroidRuntime(363): Shutting down VM
08-09 21:52:29.719: WARN/dalvikvm(363): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-09 21:52:29.790: ERROR/AndroidRuntime(363): FATAL EXCEPTION: main
08-09 21:52:29.790: ERROR/AndroidRuntime(363): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.datamonkey.android.test/com.datamonkey.android.test.actions.Statistics}: android.view.InflateException: Binary XML file line #16: Error inflating class com.datamonkey.android.test.AnalogSpeed
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.os.Looper.loop(Looper.java:123)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at java.lang.reflect.Method.invokeNative(Native Method)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at java.lang.reflect.Method.invoke(Method.java:521)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at dalvik.system.NativeStart.main(Native Method)
08-09 21:52:29.790: ERROR/AndroidRuntime(363): Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class com.datamonkey.android.test.AnalogSpeed
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.view.LayoutInflater.createView(LayoutInflater.java:513)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.app.Activity.setContentView(Activity.java:1647)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at com.datamonkey.android.test.actions.Statistics.onCreate(Statistics.java:196)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     ... 11 more
08-09 21:52:29.790: ERROR/AndroidRuntime(363): Caused by: java.lang.reflect.InvocationTargetException
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at com.datamonkey.android.test.AnalogSpeed.<init>(AnalogSpeed.java:135)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at java.lang.reflect.Constructor.constructNative(Native Method)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     at android.view.LayoutInflater.createView(LayoutInflater.java:500)
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     ... 22 more
08-09 21:52:29.790: ERROR/AndroidRuntime(363): Caused by: java.lang.NullPointerException
08-09 21:52:29.790: ERROR/AndroidRuntime(363):     ... 26 more
08-09 21:52:30.020: WARN/ActivityManager(60):   Force finishing activity com.datamonkey.android.test/.actions.Statistics
08-09 21:52:30.028: WARN/ActivityManager(60):   Force finishing activity com.datamonkey.android.test/.viewer.LoggerMap
08-09 21:52:30.589: WARN/ActivityManager(60): Activity pause timeout for HistoryRecord{44f82078 com.datamonkey.android.test/.actions.Statistics}


You have a null pointer exception: what does line 135 look like?

EDIT: My expectation is that the mHighestSpeedNumber is null, which is where the failure is happening.

0

精彩评论

暂无评论...
验证码 换一张
取 消