MyGaugeのカスタムビュークラスとRadialGaugeのカスタムクラスインポートを使用しています。以下は私のクラスコードです。
import java.awt.Color;
import java.io.IOException;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import com.softwarefx.chartfx.gauge.FileFormat;
import com.softwarefx.chartfx.gauge.GaugeFont;
import com.softwarefx.chartfx.gauge.GaugeFontSize;
import com.softwarefx.chartfx.gauge.LayoutTarget;
import com.softwarefx.chartfx.gauge.Needle;
import com.softwarefx.chartfx.gauge.NeedleStyle;
import com.softwarefx.chartfx.gauge.RadialBorderStyle;
import com.softwarefx.chartfx.gauge.RadialCapStyle;
import com.softwarefx.chartfx.gauge.RadialGauge;
import com.softwarefx.chartfx.gauge.RangeType;
import com.softwarefx.chartfx.gauge.Section;
import com.softwarefx.chartfx.gauge.TickmarkStyle;
import com.softwarefx.chartfx.gauge.Title;
public class MyGauge extends View
{
RadialGauge gauge;
public MyGauge(Context context, AttributeSet attrs)
{
super(context, attrs);
// TODO Auto-generated constructor stub
init();
}
public MyGauge(Context context)
{
super(context);
init();
}
public MyGauge(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
init();
}
public void init()
{
gauge = new RadialGauge();
//gauge.setBackColor = java.awt.Color.white;
gauge.getBorder().setColor(new java.awt.Color(230, 232, 250)); // Color Silver
Log.d("iiiiiiiiiiiiiiiii", "iiiiiiiiiiiii"+gauge);
gauge.getBorder().setGlare(true);
gauge.getBorder().setInsideColor(java.awt.Color.black) ;
gauge.getBorder().setStyle(RadialBorderStyle.getSemiCircularBorder07());
gauge.getBorder().setGlare(false);
//Setting the MainScale
gauge.getMainScale().setMax(300);
//Setting first Section
Section section1 = new Section();
section1.setMin(210);
section1.setMax(270);
section1.getBar().setColor(Color.yellow);
section1.getTickmarks().setColor(Color.white);
gauge.getMainScale().getSections().add(section1);
//Setting second Section
section1 = new Section();
section1.setMin(270);
section1.setMax(300);
section1.getBar().setColor(Color.red);
section1.getTickmarks().setColor(Color.white);
gauge.getMainScale().getSections().add(section1);
gauge.getMainScale().getBar().setVisible(false);
gauge.getMainScale().getCap().setStyle(RadialCapStyle.getRotatingCap02());
gauge.getMainScale().getCap().setColor(Color.darkGray);
Needle needle1 =(Needle) gauge.getMainIndicator();
needle1.setStyle(NeedleStyle.getNeedle10());
needle1.setUseRangeColor(RangeType.SECTION);
needle1.setValue("240");
gauge.getMainScale().getTickmarks().getMajor().setColor(Color.darkGray);
gauge.getMainScale().getTickmarks().getMajor().getLabel().setFont(new GaugeFont("Tahoma", GaugeFontSize.SMALLER, java.awt.Font.BOLD));
gauge.getMainScale().getTickmarks().getMajor().getLabel().setColor(Color.white);
gauge.getMainScale().getTickmarks().getMajor().setStep(30);
gauge.getMainScale().getTickmarks().getMajor().setStyle(TickmarkStyle.getTickmark01_2());
gauge.getMainScale().getTickmarks().getMedium().setColor(new java.awt.Color(230, 232, 250)); // Color Silver
gauge.getMainScale().getTickmarks().getMinor().setColor(Color.gray);
//Setting the titles:
Title title1 = new Title();
title1.setText("PSI");
title1.setColor(new java.awt.Color(211, 211, 211)); // Color LightGray
title1.setFont(new GaugeFont("Tahoma", GaugeFontSize.SMALLER, java.awt.Font.BOLD));
title1.getLayout().setTarget(LayoutTarget.ANCHOR_POINT);
title1.getLayout().getAnchorPoint().setLocation(0,0.225);
gauge.getTitles().add(title1);
gauge.setWidth(320);
gauge.setHeight(350);
gauge.setToolTipEnabled(false);
gauge.renderControl();
try {
gauge.exportGauge(FileFormat.XML, "file:///assets/image.bmp");
} catch (IOException e) {
Log.d("nnnnnnnnnnnnnnnnnn", "nnnnnnnnn"+gauge);
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
また、XMLファイルのカスタムビューコードは次のとおりです。
<LinearLayout android:id="@+id/gauge"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="@id/valrow2">
<view class="com.example.gaugesystems.MyGauge"
android:id="@+id/gview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Appがクラッシュしたxmlで「クラスcom.example.gaugesystems.MyGaugeを膨らませるエラー」としてエラーが発生します。なぜこれが起こっているのか誰か助けてくれませんか。
編集:以下はLogcatです:
01-15 12:32:56.515: E/AndroidRuntime(14795): FATAL EXCEPTION: main
01-15 12:32:56.515: E/AndroidRuntime(14795): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gaugesystems/com.example.gaugesystems.MyViewStatus}: android.view.InflateException: Binary XML file line #128: Error inflating class com.example.gaugesystems.MyGauge
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.app.ActivityThread.access$600(ActivityThread.java:140)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.os.Looper.loop(Looper.java:137)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.app.ActivityThread.main(ActivityThread.java:4898)
01-15 12:32:56.515: E/AndroidRuntime(14795): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 12:32:56.515: E/AndroidRuntime(14795): at java.lang.reflect.Method.invoke(Method.java:511)
01-15 12:32:56.515: E/AndroidRuntime(14795): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
01-15 12:32:56.515: E/AndroidRuntime(14795): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
01-15 12:32:56.515: E/AndroidRuntime(14795): at dalvik.system.NativeStart.main(Native Method)
01-15 12:32:56.515: E/AndroidRuntime(14795): Caused by: android.view.InflateException: Binary XML file line #128: Error inflating class com.example.gaugesystems.MyGauge
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-15 12:32:56.515: E/AndroidRuntime(14795): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:306)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.app.Activity.setContentView(Activity.java:1916)
01-15 12:32:56.515: E/AndroidRuntime(14795): at com.example.gaugesystems.MyViewStatus.onCreate(MyViewStatus.java:21)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.app.Activity.performCreate(Activity.java:5184)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
01-15 12:32:56.515: E/AndroidRuntime(14795): ... 11 more
01-15 12:32:56.515: E/AndroidRuntime(14795): Caused by: java.lang.reflect.InvocationTargetException
01-15 12:32:56.515: E/AndroidRuntime(14795): at java.lang.reflect.Constructor.constructNative(Native Method)
01-15 12:32:56.515: E/AndroidRuntime(14795): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-15 12:32:56.515: E/AndroidRuntime(14795): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
01-15 12:32:56.515: E/AndroidRuntime(14795): ... 23 more
01-15 12:32:56.515: E/AndroidRuntime(14795): Caused by: java.lang.ExceptionInInitializerError
01-15 12:32:56.515: E/AndroidRuntime(14795): at com.softwarefx.chartfx.gauge.RadialGauge.<init>(Unknown Source)
01-15 12:32:56.515: E/AndroidRuntime(14795): at com.example.gaugesystems.MyGauge.init(MyGauge.java:55)
01-15 12:32:56.515: E/AndroidRuntime(14795): at com.example.gaugesystems.MyGauge.<init>(MyGauge.java:36)
01-15 12:32:56.515: E/AndroidRuntime(14795): ... 26 more
01-15 12:32:56.515: E/AndroidRuntime(14795): Caused by: java.lang.ExceptionInInitializerError
01-15 12:32:56.515: E/AndroidRuntime(14795): at ChartFX.internal.WebForms.Gauge.BaseGauge.<clinit>(Unknown Source)
01-15 12:32:56.515: E/AndroidRuntime(14795): ... 29 more
01-15 12:32:56.515: E/AndroidRuntime(14795): Caused by: java.lang.NoClassDefFoundError: java.awt.Color
01-15 12:32:56.515: E/AndroidRuntime(14795): at SfxNETGauges.System.Drawing.Color.<clinit>(Unknown Source)
01-15 12:32:56.515: E/AndroidRuntime(14795): ... 30 more