0

活動中に奇妙な IAE を受け取りました。

08-13 16:24:59.991: E/AndroidRuntime(924): FATAL EXCEPTION: main
08-13 16:24:59.991: E/AndroidRuntime(924): java.lang.IllegalArgumentException: text cannot be null
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.graphics.Paint.measureText(Paint.java:1281)
08-13 16:24:59.991: E/AndroidRuntime(924):  at com.echo.holographlibrary.BarGraph.onDraw(BarGraph.java:151)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.View.draw(View.java:10880)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.ViewGroup.drawChild(ViewGroup.java:2899)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.ViewGroup.drawChild(ViewGroup.java:2897)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.View.draw(View.java:10883)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.widget.FrameLayout.draw(FrameLayout.java:450)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.widget.ScrollView.draw(ScrollView.java:1524)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.ViewGroup.drawChild(ViewGroup.java:2899)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.View.draw(View.java:10883)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.widget.FrameLayout.draw(FrameLayout.java:450)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.ViewGroup.drawChild(ViewGroup.java:2899)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.ViewGroup.drawChild(ViewGroup.java:2897)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2495)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.View.draw(View.java:10883)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.widget.FrameLayout.draw(FrameLayout.java:450)
08-13 16:24:59.991: E/AndroidRuntime(924):  at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2106)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.ViewRootImpl.draw(ViewRootImpl.java:2005)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1613)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2418)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.os.Looper.loop(Looper.java:137)
08-13 16:24:59.991: E/AndroidRuntime(924):  at android.app.ActivityThread.main(ActivityThread.java:4340)
08-13 16:24:59.991: E/AndroidRuntime(924):  at java.lang.reflect.Method.invokeNative(Native Method)
08-13 16:24:59.991: E/AndroidRuntime(924):  at java.lang.reflect.Method.invoke(Method.java:511)
08-13 16:24:59.991: E/AndroidRuntime(924):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-13 16:24:59.991: E/AndroidRuntime(924):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-13 16:24:59.991: E/AndroidRuntime(924):  at dalvik.system.NativeStart.main(Native Method)
08-13 16:29:41.041: I/Process(924): Sending signal. PID: 924 SIG: 9

これは以前は正常に機能していましたが、xml への動的な追加を使用したため、クラッシュしたようです。以下は呼び出しで、この例外をキャッチできませんでした。

package com.example.exercise;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Menu;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

import com.echo.holographlibrary.Bar;
import com.echo.holographlibrary.BarGraph;

public class GraphDetail extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_graph_detail);
        try{
            boolean done = false;
            int begin = 0;
            int count = 4;
            while(!done)
            {
                if(count>=MainActivity.test.size())
                {
                    done = true;
                    break;
                }
                ArrayList<Bar> points = new ArrayList<Bar>();
                Intent intent1 = getIntent();
                int max = (intent1.getIntExtra("max", 0));
                int[] weight = new int[MainActivity.test.size()];
                for(int i=begin; i<count; i++)
                {
                    weight[i] = MainActivity.test.get(i).getWeight();
                }
                String[] names = new String[MainActivity.test.size()];
                for(int i = begin; i<count; i++)
                {
                    names[i] = MainActivity.test.get(i).getName();
                }

                for(int i = 0; i< weight.length; i++)
                {
                    Bar d = new Bar();
                    if(weight[i]!=max)
                        d.setColor(Color.parseColor("#99CC00"));
                    else
                    {
                        d.setColor(Color.parseColor("#FFBB33"));
                    }

                    d.setName(names[i]);
                    d.setValue(weight[i]);
                    points.add(d);
                }
                Resources r = getResources();
                float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 130, r.getDisplayMetrics());
                RelativeLayout rl = (RelativeLayout)findViewById(R.id.container);
                int px1 = (int)px;
                BarGraph bar = new BarGraph(this);
                LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, 
                        px1);
                bar.setBars(points);

                bar.setUnit("0");
                bar.appendUnit(true);
                rl.addView(bar, lp);

                begin+=count;
                count+=3;
                if(count>=MainActivity.test.size())
                {
                    done = true;
                    break;
                }
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

//          ArrayList<Bar> points = new ArrayList<Bar>();
//          ArrayList<Bar> points1 = new ArrayList<Bar>();
//          ArrayList<Bar> points2 = new ArrayList<Bar>();
//          Intent intent1 = getIntent();
//          int max = (intent1.getIntExtra("max",0));
//          int[] weight = new int[MainActivity.test.size()];
//          for(int i = 0; i<MainActivity.test.size(); i++)
//          {
//              weight[i] = MainActivity.test.get(i).getWeight();
//          }
//          String[] names = new String[MainActivity.test.size()];
//          for(int i = 0; i<MainActivity.test.size(); i++)
//          {
//              names[i] = MainActivity.test.get(i).getName();
//          }
//          for(int i = 0; i< weight.length; i++)
//          {
//              Bar d = new Bar();
//              if(weight[i]!=max)
//                  d.setColor(Color.parseColor("#99CC00"));
//              else
//              {
//                  d.setColor(Color.parseColor("#FFBB33"));
//              }
//                  
//              d.setName(names[i]);
//              d.setValue(weight[i]);
//              if(i<4)
//                  points.add(d);
//              if(i>=4 && i<8)
//                  points1.add(d);
//              if(i>=8)
//                  points2.add(d);
//          }
//          BarGraph g = (BarGraph) findViewById(R.id.graph);
//          g.setBars(points);
//          BarGraph g1 = (BarGraph) findViewById(R.id.graph1);
//          g1.setBars(points1);
//          BarGraph g2 = (BarGraph) findViewById(R.id.graph2);
//          g2.setBars(points2);
//          g.setUnit("0");
//          g.appendUnit(true);
//          g1.setUnit("0");
//          g1.appendUnit(true);
//          g2.setUnit("0");
//          g2.appendUnit(true);
//      


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.graph_detail, menu);
        return true;
    }

}
4

1 に答える 1