我正在GenericObjectPool
通过放入Cipher
池进行研究,以便可以重复使用.
GenericObjectPool<Cipher> pool;
CipherFactory factory = new CipherFactory();
this.pool = new GenericObjectPool<Cipher>(factory);
pool.setMaxTotal(10);
pool.setBlockWhenExhausted(true);
pool.setMaxWaitMillis(30 * 1000);
Run Code Online (Sandbox Code Playgroud)
CipherFactory
public class CipherFactory extends BasePooledObjectFactory<Cipher> {
private boolean running = false;
@Override
public Cipher create() throws Exception {
return Cipher.getInstance("DESede/CBC/NoPadding");
}
@Override
public PooledObject<Cipher> wrap(Cipher arg0) {
return new DefaultPooledObject<Cipher>(arg0);
}
@Override
public boolean validateObject(PooledObject<Cipher> p) {
//Ensures that the instance is safe to be returned by the pool
return true;
}
@Override
public void destroyObject(PooledObject<Cipher> p) { …
Run Code Online (Sandbox Code Playgroud) 我使用了这个库中的演示,它工作得很好。但是当我在我的项目中实施时,我在这一行出现错误
错误:不是常量表达式。const AssetImage(snapshot.data[index]),
我的Container
正在包装中InkWell
。
InkWell(
child: Container(
padding:
EdgeInsets.zero,
height: 150,
width: 150,
decoration:
BoxDecoration(
image: DecorationImage(
image: AssetImage(snapshot.data[index]),
fit: BoxFit .fill),
),
),
onTap: () {
print('The value is ' + snapshot .data[index]);
Navigator.push(
context,
MaterialPageRoute(
builder:
(context) =>
const FullScreenWrapper(imageProvider:const AssetImage(snapshot.data[index]), // here the error
)));
},
),
Run Code Online (Sandbox Code Playgroud)
这里的打印值
值为/storage/emulated/0/Android/data/xxx/files/Pictures/scaled_1572364487252xxx.jpg
如果我删除const,我会收到其他错误
常量创建的参数必须是常量表达式。尝试使参数成为有效的常量,或使用“new”来调用构造函数。
我什至尝试使用new
但无济于事。
我想使用此处描述的迁移工具。
但我得到Error: Error when reading 'migrate': No such file or directory
这是我的 dart 版本和错误
xxx@xxx-:~/Desktop/xxx$ dart --version
Dart VM version: 2.4.0 (Unknown timestamp) on "linux_x64"
xxx@xxx-I:~/Desktop/xxx$ dart migrate
Error: Error when reading 'migrate': No such file or directory
Run Code Online (Sandbox Code Playgroud)
pubspec.yaml
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
Run Code Online (Sandbox Code Playgroud) 我希望我了解如何didChangeAppLifecycleState
正确工作。
我有页面 A 和页面 B 。当我单击页面 B ( Navigator.of(context).pop();
) 中的后退设备按钮时,我希望didChangeAppLifecycleState
在页面 A中会被调用,但事实并非如此。
页面A
class _ABCState extends State<ABCrList> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
....
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
setState(() {
print(...);
});
}else{
print(state.toString());
}
}
....
Run Code Online (Sandbox Code Playgroud)
这是initState
在页面A。用于调用后端服务的函数。
@override
void initState() {
super.initState();
_bloc.getList(context); // return list and populate to ListView
});
}
Run Code Online (Sandbox Code Playgroud) 为什么底部导航栏标题不显示?它假设显示在图标下方
class FlutterProject extends StatefulWidget {
final String title = "Flutter Bottom Tab demo";
@override
GoalsListState createState() {
return GoalsListState();
}
}
class GoalsListState extends State<FlutterProject>
with SingleTickerProviderStateMixin {
int _cIndex = 0;
void _incrementTab(index) {
setState(() {
_cIndex = index;
});
}
final List<Widget> _children = [
new One(),
new Two(),
new Three(),
new Four(),
new More()
];
@override
Widget build(BuildContext context) {
return new Scaffold(
body: _children[_cIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _cIndex,
type: BottomNavigationBarType.shifting,
items: [
BottomNavigationBarItem(
icon:
Icon(Icons.graphic_eq, …
Run Code Online (Sandbox Code Playgroud) 这是什么类型的日期格式?
2020-03-26T00:57:08.000+08:00
Run Code Online (Sandbox Code Playgroud)
我正在使用DateFormat类
DateTime dateTime = DateTime.now();
print(dateTime.toIso8601String());
print(dateTime.toLocal());
print(dateTime.toUtc());
Run Code Online (Sandbox Code Playgroud)
输出
I/flutter (20667): 2020-03-26T01:34:20.826589
I/flutter (20667): 2020-03-26 01:34:20.826589
I/flutter (20667): 2020-03-25 17:34:20.826589Z
Run Code Online (Sandbox Code Playgroud)
我想要一个像我显示的第一个输出一样的日期格式,后面有+08:00。我应该使用哪个?
错误Error incompatible types: android.app.FragmentManager cannot be converted to android.support.v4.app.FragmentManager
让我疯了.
在我的应用程序中,我有3个导航抽屉项目timesheet
,claim
并view
在MainActivity中创建.现在,我想添加两个tabs
与swipe view
的view
项目.
MainActivity //用于导航抽屉
import android.app.Fragment;
import android.app.FragmentManager;
private void selectItem(int position) {
Fragment fragment = null;
switch (position) {
case 0:
fragment=new TimeSheet();
break;
case 1:
fragment=new Claims1();
break;
case 2:
fragment=new Viewview();
break;
default:
break;
}
Run Code Online (Sandbox Code Playgroud)
TabsFragmentPagerAdapter.java
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
public class TabsFragmentPagerAdapter extends FragmentPagerAdapter {
public TabsFragmentPagerAdapter(FragmentManager fm) {
super(fm);
// …
Run Code Online (Sandbox Code Playgroud) 跟进此问题,LogBack Syslog无法正常工作
我使用下面的命令syslog
在ubuntu
16.04中查看,但得到以下结果。这是正确的观看方式吗?
user@xxx:~$ tail -f /var/log/syslog Jun 6 23:08:50 xxx systemd[1]:
Starting Hostname Service... Jun 6 23:08:50 xxx dbus[889]: [system]
Successfully activated service 'org.freedesktop.hostname1' Jun 6
23:08:50 xxx systemd[1]: Started Hostname Service. Jun 6 23:09:41 xxx
gnome-session[2645]: (nautilus:2860): Gtk-WARNING **: Attempting to
read the recently used resources file at
'/home/xxx/.local/share/recently-used.xbel', but the parser failed:
Failed to open file '/home/xxx/.local/share/recently-used.xbel':
Permission denied. Jun 6 23:09:41 xxx org.gtk.vfs.Daemon[2508]:
(gvfsd-recent:15282): Gtk-WARNING **: Attempting to read the recently …
Run Code Online (Sandbox Code Playgroud) 我想在颤振中绘制折线图。我遵循本教程,如果日期和月份不同,它可以正常工作。
但是为什么如果它只有一个日期和一个点,图表会变成这个?
代码
/// Timeseries chart example
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
title: 'My app', // used by the OS task switcher
theme: ThemeData(
accentIconTheme: const IconThemeData.fallback().copyWith(
color: Colors.white,
),
primaryTextTheme: TextTheme(title: TextStyle(color: Colors.white)),
primarySwatch: Colors.orange,
primaryIconTheme: const IconThemeData.fallback().copyWith(
color: Colors.white,
),
),
home: SimpleTimeSeriesChart()),
);
}
class SimpleTimeSeriesChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var seriesList = List<Data>();
seriesList.add(Data(DateTime(2020, 03, 12), int.parse("50")));
return Scaffold(
appBar: AppBar(
title: Text("Graph"),
), …
Run Code Online (Sandbox Code Playgroud) 我正在尝试检索SQLite值并加载到listView MainActivity.我正在按照本教程.
但是,当我的应用程序刚刚开始时,它崩溃并显示出来Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
.
好像我还没有初始化listView.setAdapter
.我检查了教程,仍然无法弄清楚我在这里错过了什么.
活动A.
public class MainActivity extends AppCompatActivity {
InfoAPI sqlcon;
private SimpleCursorAdapter dataAdapter;
private SQLiteDatabase database;
private MyDatabaseHelper dbHelper;
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listView=(ListView)findViewById(R.id.listView2);
setContentView(R.layout.activity_main);
dbHelper = new MyDatabaseHelper(this);
sqlcon = new InfoAPI(this);
BuildList();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action …
Run Code Online (Sandbox Code Playgroud) sqlite android listview nullpointerexception android-listview
我正在尝试navigation drawer
在我的应用程序中创建。在我的一个navigation drawer item
,View
我希望它有2个tabs
与swipe view
功能。我可以单独创建它们,但是当我尝试在 1 中执行时,出现错误。
MainActivity // 用于导航抽屉项
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
private void selectItem(int position) {
Fragment fragment = null;
switch (position) {
case 0:
fragment=new Information();
break;
case 1:
fragment=new Claims1();
Bundle bundle=new Bundle();
bundle.putLong("ab",WorkDetailsTable.ab);
fragment.setArguments(bundle);
break;
case 2:
fragment=new ViewView();
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(mNavigationDrawerItemTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
} else {
Log.e("MainActivity", "Error …
Run Code Online (Sandbox Code Playgroud) 我的闹钟设计布局listView
如下图所示.
custom_row_view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp">
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="Time"
android:paddingLeft="40dp"
android:paddingTop="15dp"
android:textColor="@color/black"
android:textStyle="bold"
/>
<ToggleButton
android:id="@+id/switchAlarm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff=""
android:textOn=""
android:layout_marginLeft="200dp"
android:drawableTop="@mipmap/switch_alarm"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Text"
android:id="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Text"
android:layout_marginRight="@+id/textView"
android:id="@+id/textView1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Text"
android:layout_marginRight="@+id/textView1"
android:id="@+id/textView2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Text"
android:layout_marginRight="@+id/textView2"
android:id="@+id/textView3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceSmall" …
Run Code Online (Sandbox Code Playgroud) 我通过使用以下代码保存图像uri
public void insert (Uri image) throws SQLiteException {
SQLiteDatabase database = mdb.getWritableDatabase();
ContentValues cv = new ContentValues();
try {
InputStream iStream = getContentResolver().openInputStream(image);
byte[] inputData = com.example.tony.monthlyexpenses.Utils.getBytes(iStream);
cv.put(MyDatabaseHelper.KEY_IMAGE,inputData);
}catch(IOException ioe)
{
Log.e("A", "<saveImageInDB> Error : " + ioe.getLocalizedMessage());
}
database.insert(MyDatabaseHelper.TABLE_EXPENSES, null, cv);
database.close();
}
Run Code Online (Sandbox Code Playgroud)
实用程序
public static Bitmap getImage(byte[] image) {
return BitmapFactory.decodeByteArray(image, 0, image.length);
}
public static byte[] getBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int …
Run Code Online (Sandbox Code Playgroud)