1

我正在尝试从视图创建 BitmapDescriptor。

这是代码:

            LayoutInflater inflater = (LayoutInflater)myActivity.getApplicationContext().getSystemService (Context.LAYOUT_INFLATER_SERVICE); 

            View myView= inflater.inflate(R.layout.myview,null);

            if (myView== null) Log.d("myViewcheck", "null");
                else Log.d("myViewcheck", myView.toString());

            myView.setDrawingCacheEnabled(true);

        102--->   myView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));             
            myView.layout(0, 0, myView.getMeasuredWidth(), myView.getMeasuredHeight()); 

            myView.buildDrawingCache(true);

            Bitmap b = Bitmap.createBitmap(myView.getDrawingCache());

这是我收到的错误日志

04-26 12:07:22.989: W/dalvikvm(19048): threadid=23: thread exiting with uncaught exception (group=0x40018560)
04-26 12:07:23.129: E/AndroidRuntime(19048): FATAL EXCEPTION: AsyncTask #1
04-26 12:07:23.129: E/AndroidRuntime(19048): java.lang.RuntimeException: An error occured while executing doInBackground()
04-26 12:07:23.129: E/AndroidRuntime(19048):    at android.os.AsyncTask$3.done(AsyncTask.java:200)
04-26 12:07:23.129: E/AndroidRuntime(19048):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
04-26 12:07:23.129: E/AndroidRuntime(19048):    at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
04-26 12:07:23.129: E/AndroidRuntime(19048):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
04-26 12:07:23.129: E/AndroidRuntime(19048):    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
04-26 12:07:23.129: E/AndroidRuntime(19048):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
04-26 12:07:23.129: E/AndroidRuntime(19048):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
04-26 12:07:23.129: E/AndroidRuntime(19048):    at java.lang.Thread.run(Thread.java:1019)
04-26 12:07:23.129: E/AndroidRuntime(19048): Caused by: java.lang.NullPointerException
04-26 12:07:23.129: E/AndroidRuntime(19048):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:431)
04-26 12:07:23.129: E/AndroidRuntime(19048):    at android.view.View.measure(View.java:8313)
04-26 12:07:23.129: E/AndroidRuntime(19048):    at it.mypkg.utils.MapPopulatorAsyncTask.doInBackground(MapPopulatorAsyncTask.java:102)
04-26 12:07:23.129: E/AndroidRuntime(19048):    at it.mypkg.utils.MapPopulatorAsyncTask.doInBackground(MapPopulatorAsyncTask.java:1)
04-26 12:07:23.129: E/AndroidRuntime(19048):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-26 12:07:23.129: E/AndroidRuntime(19048):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
04-26 12:07:23.129: E/AndroidRuntime(19048):    ... 4 more

由于 myView 不为空,任何人都可以建议我如何调试我的代码???

谢谢!!

4

0 回答 0