public class MapActivity extends Activity implements LocationListene
ロードしたい onCreate メソッドの場所があります。
protected void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
...
}
}
mapview.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ll_mapView"
android:background="@android:color/white">
<another_working_layout_here>
<map.MyLocation
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</map.MyLocation>
</LinearLayout>
そして、クラスからビューがロードされると:
public class MyLocation extends View {
Paint paint = new Paint();
public MyLocation(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.FILL);
canvas.drawCircle(100, 100, 100, paint);
this.invalidate();
}
}
一般に、mapActivity のメソッドを使用して Android GPS から読み取りonLocationChanged
、変更点を追加し、後で onDraw メソッドで実行された拡張ビューに印刷したいと考えてclass MyLocation extends View
います。私はこの概念を完全には理解していないと確信していますが、これを別の方法で行う方法がわかりません。
私のエラーは次のとおりです。
10-28 16:06:40.147: ERROR/myException(2869): android.view.InflateException: Binary XML file line #26: Error inflating class map.MyLocation
10-28 16:07:06.478: ERROR/ActivityManager(1120): ANR in com.example.gps_3 (com.example.gps_3/activities.MapActivity)
Reason: keyDispatchingTimedOut
Load: 0.26 / 0.25 / 0.76
CPU usage from 39586ms to 535ms ago:
2.2% 950/adbd: 0% user + 2.2% kernel
0% 932/yaffs-bg-1: 0% user + 0% kernel
0.1% 2869/com.example.gps_3: 0% user + 0.1% kernel / faults: 18 minor
0.1% 1120/system_server: 0% user + 0% kernel
0% 1391/com.android.phone: 0% user + 0% kernel / faults: 92 minor
0% 930/yaffs-bg-1: 0% user + 0% kernel
0% 1281/com.android.systemui: 0% user + 0% kernel / faults: 6 minor
0% 1404/com.android.launcher: 0% user + 0% kernel
0% 2789/com.android.browser: 0% user + 0% kernel / faults: 89 minor
48% TOTAL: 0.6% user + 45% kernel + 1.8% softirq
CPU usage from 403ms to 914ms later:
1.9% 1120/system_server: 0% user + 1.9% kernel
100% TOTAL: 0% user + 100% kernel
10-28 16:12:04.312: ERROR/dalvikvm(1120): JIT code cache full
10-28 16:12:04.322: ERROR/InputDispatcher(1120): channel 'b353cf20 com.example.gps_3/activities.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
10-28 16:12:04.322: ERROR/InputDispatcher(1120): channel 'b350af88 com.example.gps_3/activities.MapActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
10-28 16:12:05.092: ERROR/jdwp(2914): Failed sending reply to debugger: Broken pipe
10-28 16:13:04.613: ERROR/myException(2914): android.view.InflateException: Binary XML file line #26: Error inflating class map.MyLocation
編集:
例外は次の場所で呼び出されます:
@Override
protected void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
myLocationManager = (LocationManager) this.getSystemService(this.LOCATION_SERVICE);
myLocationLister = this;
myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, myLocationLister);
} catch (Exception e) {
Log.e("myException", e.toString());
}
}
行 setContentView(R.layout.mapview);
ごと。
アイデアをいただければ幸いです。ありがとう
問題はコンストラクターの欠落にありました:
public MyLocation(Context context, AttributeSet attrs) {
super(context, attrs);
}