我在 Android Studio 4.2.2 上。我创建了一个新项目并且没有在启动代码中添加任何内容,每当我单击build 或 run 时,我都会收到此错误:
安装的构建工具修订版 31.0.0 已损坏。使用 SDK Manager 删除并重新安装。
我看过其他帖子的建议,但这些解决方案都没有奏效。这是我尝试过的:
rm -rf /path/to/android/sdk/build-tools/31.0.0(它不像其他一些帖子描述的那样以“-rc”结尾)我是一个 Android 菜鸟,只是想建立一个 hello world 项目,这真的不应该这么难。
在https://java-programming.mooc.fi/part-10/2-interface-comparable上做练习“文学”时,我在尝试对 HashMap 中的键值对进行排序时发现了一个非常奇怪的行为,而没有将任何内容复制到一个树形图。我应该通过创建 Book 类并将它们添加到 List 来添加书籍。但是我想在不创建新类的情况下尝试,所以选择了 HashMap。我的代码如下:
public class MainProgram {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Map<String, Integer> bookshelf = new HashMap<>();
while (true) {
System.out.println("Input the name of the book, empty stops: ");
String bookName = scanner.nextLine();
if (bookName.equals("")) {
break;
}
System.out.println("Input the age recommendation: ");
int age = Integer.valueOf(scanner.nextLine());
bookshelf.put(bookName, age);
}
System.out.println(bookshelf.size() + " book" + (bookshelf.size() > 1 ? "s" : "") + " in total."); …Run Code Online (Sandbox Code Playgroud) 我在 gorm 中有一个事务表,如下所示:
type Transaction struct {
gorm.Model
UserID string `gorm:"index"`
TradeID int
Trade Trade
ExternalID string
Amount float32
Type string
Description string
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试插入一笔没有交易的交易:
DB.Create(&Transaction{UserID: "user-1", Type: "unblock", Amount: 50})
Run Code Online (Sandbox Code Playgroud)
这会失败,因为事务结构将键的 int 值默认为 0,因此插入在数据库级别失败,因为我没有 id = 0 的交易。
我怎样才能做到这一点?
我正在试验 Java 中的递归,我有这个方法:
public static int recursion(int n) {
if(n==1) {
return 2;
} else {
int test = (recursion(n-1))/(recursion(n-1));
return test;
}
}
Run Code Online (Sandbox Code Playgroud)
如果我用 运行它n = 50,它永远不会打印任何东西,所以我猜递归调用是无限的?有人能解释一下为什么吗?
我有一个带有库的服务器端 Blazor.NET 应用程序(dotnet core 3.1): ProtectedBrowserStorage ( https://www.nuget.org/packages/Microsoft.AspNetCore.ProtectedBrowserStorage ) 用于客户端浏览器中的加密存储
有时我的日志文件中会出现如下错误:
2020-04-01 14:05:17.4809 Error System.Threading.Tasks.TaskCanceledException: A task was canceled.
at Microsoft.JSInterop.JSRuntime.InvokeWithDefaultCancellation[T](String identifier, Object[] args)
at Microsoft.AspNetCore.ProtectedBrowserStorage.ProtectedBrowserStorage.GetAsync[T](String purpose, String key)
at PegasusV6.LocalStorageService.LoadBasket(MenuDTO menu) in LocalStorageService.cs:line 40 A task was canceled.
Run Code Online (Sandbox Code Playgroud)
我的问题是我不知道是什么导致了 JavaScript 调用中的这个错误。
是否有可以修复此类错误的服务器限制?
或者是客户端用户可能没有良好的互联网速度/连接,这是服务器端 Blazor 非常需要的?
希望有人能给我一个提示或任何可以改进它的东西。这是调用的 C# 函数:
public async Task LoadBasket(MenuDTO menu)
{
try
{
AppState.BasketData = await ProtectedLocalStore.GetAsync<BasketState>($"Basket_{My.StoreId}") ?? new BasketState();
}
catch (Exception ex)
{
My.Log.Error(ex);
AppState.BasketData = new BasketState();
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
省略不工作。
检索错误:
struct deliveryFood/models.Restaurant 的字段 DeliveryZone 发现无效字段,需要为关系定义外键或需要实现 Valuer/Scanner 接口
type Restaurant struct {
ID uint
Name string `json:"name"`
EmployeeId uint `json:"employee_id"`
Phone string `json:"phone"`
Address string `json:"address"`
ImagesUrl *string `json:"images_url"`
Position string `json:"position"`
WorkDays string `json:"work_days"`
StartWorkTime string `json:"start_work_time"`
EndWorkTime string `json:"end_work_time"`
Blocked bool `json:"blocked"`
DeliveryZone []*DeliveryZone `json:",omitempty"`
}
type DeliveryZone struct {
ID uint `json:"id"`
RestaurantId uint `json:"restaurant_id"`
Zone string `json:"zone"`
Price float32 `sql:"-"`
}
Run Code Online (Sandbox Code Playgroud)
err := GetDB().Omit(clause.Associations).Model(Restaurant{}).Create(map[string]interface{} {
"name": rest.Name,
"EmployeeId": rest.EmployeeId,
"Phone": rest.Phone,
"Address": rest.Address,
"ImagesUrl": rest.ImagesUrl, …Run Code Online (Sandbox Code Playgroud) 我有一个List<Map<String,String>>
这样的:
Map<String, String> m1 = new HashMap<>();
m1.put("date", "2020.1.5");
m1.put("B", "10");
Map<String, String> m2 = new HashMap<>();
m2.put("date", "2020.1.5");
m2.put("A", "20");
Map<String, String> m3 = new HashMap<>();
m3.put("date", "2020.1.6");
m3.put("A", "30");
Map<String, String> m4 = new HashMap<>();
m4.put("date", "2020.1.7");
m4.put("C", "30");
List<Map<String, String>> before = new ArrayList<>();
before.add(m1);
before.add(m2);
before.add(m3);
before.add(m4);
Run Code Online (Sandbox Code Playgroud)
我期望的结果是生成一个新的 List 映射,该映射按 date 分组,并将同一日期中设置的所有条目放在一起,例如:
[{"A":"20","B":"10","date":"2020.1.5"},{"A":"30","date":"2020.1.6"},{"C":"30","date":"2020.1.7"}]
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法,但始终不是我期望的结果。
stream().flatmap().collect(Collectors.groupingBy())
Run Code Online (Sandbox Code Playgroud)
对这个问题的一些附加评论:
我为 LOOP 解决了这个问题,但是当列表大小约为 50000 时应用程序挂起,所以我寻求一种更好的性能方法来做到这一点。据我所知,Java 8 流平面地图可能是一种方式。所以关键不仅是重新映射这个,而且是用最高效的方式来做到这一点。
我正在尝试了解 java8 流,想知道是否有人可以帮助我。
在旧的java中,
List<Obj> newObjs = ArrayList<Obj>();
for (Obj obj : objects){
if(obj == null){
logger.error("null object");
}
else{
newObjs.add(...)
}
}
Run Code Online (Sandbox Code Playgroud)
基本上,我想过滤空对象并记录它。在 java 8 中执行此操作的好方法是什么?
根据GORM 的文档:
Updates支持使用struct或map[string]interface{}更新,使用struct更新时默认只更新非零字段
我的数据库中已有一个ServiceID 为 的条目abc123。我正在尝试获取一个如下所示的对象:
Service{
ID: "abc123",
Name: "new service name",
CreatedAt: nil,
}
Run Code Online (Sandbox Code Playgroud)
并用它来更新我现有的记录。但是当我打电话时:
tx.Model(&service).Updates(service)
Run Code Online (Sandbox Code Playgroud)
CreatedAt数据库中的值将被覆盖nil。如何更新数据库记录而不覆盖该CreatedAt值?
更新:下面是我的Service结构
type Service struct {
ID string `gorm:"not null;type:char(32);primary_key;column:id"`
Name string `json:"name" gorm:"size:50;not null;"`
CreatedAt *time.Time
UpdatedAt time.Time
DeletedAt *time.Time `gorm:"index"`
}
Run Code Online (Sandbox Code Playgroud)
我已经为我的Service结构尝试了两种不同的变体。另一个是与CreatedAt类型time.Time而不是*time.Time。它将用*time.Time空值覆盖我的数据库中的值。它尝试用time.Time未初始化的时间值覆盖数据库中的值并抛出错误:Error 1292: Incorrect datetime value: '0000-00-00' for column 'created_at' at row 1
我正在尝试编写 Gorm 自定义数据类型:https : //gorm.io/docs/data_types.html
type MyDataType struct {}
func (f *MyDataType) Scan(value interface{}) error {
//
}
func (f MyDataType) Value() (driver.Value, error) {
//
}
Run Code Online (Sandbox Code Playgroud)
由于某些原因,我需要访问上下文Scan或能够检索字段标签。
有没有办法做到这一点 ?谢谢
go ×4
go-gorm ×4
java ×4
java-stream ×3
java-8 ×2
android ×1
blazor ×1
collectors ×1
groupingby ×1
hashmap ×1
postgresql ×1
recursion ×1
sorting ×1