1
私はアンドロイドが新しく、電話機の場所をデータベースに保存して位置を表示しようとしています。ListView
。 が、私はこの例外を持つアプリケーションをruningています:java.lang.IllegalStateException: System services not available to Activities before onCreate()
IllegalStateException:私のアプリケーションを実行しようとしているときに、onCreate()の前にアクティビティで利用できないシステムサービス
と私は、この行への参照を持っている:
layoutInflater = LayoutInflater.from(context);
この行はMyCursorAdapter
クラスです。
public class MainActivity extends AppCompatActivity
{
public static Cursor cursor;
public static DBHelper dbHelper;
public static ListView listView;
public LocationsControl locationsControl;
public SQLiteDatabase database;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView)findViewById(R.id.listView);
this.dbHelper = new DBHelper(this.getApplicationContext());
database = dbHelper.getReadableDatabase();
cursor = database.query(Locations.LocationsEntry.TABLE_NAME,null,null,null,null,null,null);
MyCursorAdapter myCursorAdapter = new MyCursorAdapter(this,cursor);
listView.setAdapter(myCursorAdapter);
locationsControl = new LocationsControl(this.getApplicationContext());
}
public void fillListView()
{
cursor = dbHelper.getAllTheData();
if(cursor != null)
{
MyCursorAdapter myCursorAdapter = new MyCursorAdapter(this,cursor);
myCursorAdapter.notifyDataSetChanged();
}
}
}
そして、ここではMyCursorAdapterクラスである:ここで
は私MainActivity
コードです
public class MyCursorAdapter extends CursorAdapter
{
public static TextView longitude;
public static TextView latitude;
public static TextView timeAndDate;
LayoutInflater layoutInflater;
public MyCursorAdapter(Context context, Cursor cursor)
{
super(context,cursor);
layoutInflater = LayoutInflater.from(context);//Here the problem
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent)
{
return layoutInflater.inflate(R.layout.list_black_text,parent,false);
}
@Override
public void bindView(View view, Context context, Cursor cursor)
{
longitude = (TextView)view.findViewById(R.id.textView4);
latitude = (TextView)view.findViewById(R.id.textView5);
timeAndDate = (TextView)view.findViewById(R.id.textView6);
longitude.setText(""+cursor.getDouble(cursor.getColumnIndex(Locations.LocationsEntry.LONGITUDE)));
latitude.setText(""+cursor.getDouble(cursor.getColumnIndex(Locations.LocationsEntry.LATITUDE)));
timeAndDate.setText(""+cursor.getString(cursor.getColumnIndex(Locations.LocationsEntry.DATE_AND_TIME)));
}
}
私はオンラインの答えを探したが、私は見つかったすべての答えは、私を助けてくれませんでした。
は多分にに相当するものを試してください: 'LayoutInflater.fromを返す(コンテキスト).inflate(R.layout.activity_aisle_list_entry、親、偽);' 'すなわちLayoutInflaterを返します。 .inflate(R.layout.list_black_text、parent、false); '1)大文字Lと2)渡されたコンテキストを使用します。 – MikeT
@MikeTここで私がやったことと同じ問題が残っています:public View newView(Context context、Cursor cursor、ViewGroup parent) { return LayoutInflater.from(context).inflate(R.layout.list_black_text、parent、false ); } ' – Fincha