我在使用OpenWeatherMap API时遇到此异常错误.我只是想让结果成为一个JSONObject,但是null仍然会出现.
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// What's coming in as result...
// Printed to the console...
// null{"coord":{"lon":-0.13,"lat":51.51},"weather":[{"id":800,"main":"Clear",
// "description":"clear sky","icon":"01d"}],...}
try {
JSONObject jsonObject = new JSONObject(result);
String weatherInfo = jsonObject.getString("weather");
Log.i("Weather Info", weatherInfo);
} catch (JSONException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
JSON数据很好,但我想要的是它成为一个JSONObject但是null部分正在捕获.任何想法为什么会发生这种情况?
同样来自网站的JSON Response是:
{"coord":{"lon":-0.13,"lat":51.51},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],.....}
Run Code Online (Sandbox Code Playgroud)
为什么一开始没有null?谢谢您的帮助.
最近我用DialogFlow用完了项目空间构建聊天机器人.我不认为我在Google Cloud上使用最好的标准项目(任何提示都会很棒!)因为我尝试创建一个新的聊天机器人,它会告诉我我已经没有项目空间了.
是否可以将这些聊天机器人置于相同的项目ID下?保持项目低,同时仍然可以制作聊天机器人?
谢谢
我一直在四处寻找,试图找出我的代码导致问题的原因.我有一个GridView,它有一个ArrayAdapter,可以使用AsyncTask将照片拉下来.我可以看到正在更新的项目,但是当我尝试更新适配器时,GridView似乎没有使用新视图更新.
这是完成工作的相关代码......
private void fetchJsonResponse(String url) {
// Pass second argument as "null" for GET requests
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET,
url + "&api_key=" + API_KEY,
null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray photos = response.getJSONArray("photos");
for(int i = 0; i < photos.length(); i++){
JSONObject object = photos.getJSONObject(i);
String url = object.getString("img_src");
//String id = object.getString("id");
list.add(new ImageItem(null, "Picture", url));
Log.i("Debug 2", url);
}
Log.i("Debug 2", list.get(0).toString());
if(gridViewAdapter != null){
gridViewAdapter.clear();
gridViewAdapter.addAll(list);
gridViewAdapter.notifyDataSetChanged();
gridView.invalidateViews(); …Run Code Online (Sandbox Code Playgroud) 我们有 composer 作为我们的依赖注入框架,它将引入我们创建的库 foobar,它工作正常。库 foobar 有 14 个版本 v1.1.1 -> v1.1.14。一直到 0.12 composer 更新了应用程序。但是现在我们收到了这个错误......
Update failed (Source directory /home/username/dev/git/appname/vendor/foorbar/library has unpushed changes on the current branch:
Branch v1.1.14 could not be found on the origin remote and appears to be unpushed)
Run Code Online (Sandbox Code Playgroud)
须知:
有没有人遇到过这个问题,你是如何解决的?
谢谢
我曾多次尝试让这些测试运行。我只是真的不确定,似乎无法找到为什么它是错误的。我在 Ionic 应用程序上使用存储模块,当尝试将其添加到单元测试时,出现以下错误。我很迷失所以任何帮助都会非常感激。
NullInjectorError:StaticInjectorError(DynamicTestModule)[AuthService -> Storage]:StaticInjectorError(平台:核心)[AuthService -> Storage]:NullInjectorError:没有存储提供者!
import { TestBed, fakeAsync, tick, inject } from '@angular/core/testing';
import {
HttpClientTestingModule,
HttpTestingController,
} from '@angular/common/http/testing';
import { AuthService } from './auth.service';
import { HttpErrorResponse } from '@angular/common/http';
import { IonicStorageModule } from '@ionic/Storage';
import { of } from 'rxjs';
describe('AuthServiceService', () => {
let service: AuthService;
let httpTestingController: HttpTestingController;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
AuthService
],
imports: [
HttpClientTestingModule,
IonicStorageModule.forRoot()
],
});
httpTestingController = TestBed.get(HttpTestingController);
service = TestBed.get(AuthService);
});
it('should …Run Code Online (Sandbox Code Playgroud) 我有两个提供者,一个是 EntriesProvider,另一个是 EntryProvider。我在创建条目时使用我的 EntryProvider 和我的 EntriesProvider 来加载保存到数据库的所有条目。我遇到了一个问题,我认为这可能是我对如何使用 Providers 的理解。一旦我将我的数据库数据加载到我的 EntriesProvider 中,我就会将该数据加载到 ListView 中。单击某个项目后,我将该列表中的条目传递到我的视图中以进行填充和编辑。
我的问题是,当我在不保存的情况下编辑条目时,我可以看到 ListView 中发生的更改,这不是我想要的。我尝试清除 EntryProvider,因为我认为属于它的数据与 EntriesProvider 是分开的。但是现在我在尝试了很多事情之后不知道了。当我只要求 EntryProvider 更新其侦听器时,为什么要更新列表?
class EntryProvider extends ChangeNotifier {
Entry _entry;
BuildContext context;
EntryProvider();
Entry get getEntry {
return _entry;
}
void setEntryContext(Entry entryToBeSet, BuildContext context) {
this._entry = entryToBeSet;
this.context = context;
notifyListeners();
}
void clearEntryContext() {
this._entry = null;
this.context = null;
notifyListeners();
}
void addImageToEntry(String imagePath) {
getEntry.images.add(imagePath);
notifyListeners();
}
void removeImageAt(int index) { …Run Code Online (Sandbox Code Playgroud) 我似乎无法让这个工作:
public string Convert(){
var output = "";
if(input.Length < 1){
output = "Enter a number!";
}
else {
try {
var result = Convert.ToDouble(input) * 0.69;
output = "$ " + input + " converted to £ " + result;
} catch(Exception e){
output = "Enter a number!";
Console.WriteLine ("Error in conversion: " + e.Message);
}
}
return output;
}
Run Code Online (Sandbox Code Playgroud)
我只想让var结果部分工作,但无论如何我都会得到以下错误.
错误CS0023:'.' operator不能应用于`method group'类型的操作数(CS0023)(CurrencyConverter.Droid)
谢谢你的帮助!
我在 RecyclerView 中有一个字符串列表。我需要能够单击列表中的项目并更改背景黄色。我可以单击一个项目并更改背景,但是当我向下滚动列表时,我看到列表中的另一个项目的背景也变成了黄色?
我尝试了许多不同的方法来实现这一点。我尝试设置一个界面,点击 ViewHolder 等。
我的代码如下。
活动:
[Activity(Label = "PregnancyListActivity")]
public class PregnancyListActivity : Activity
{
RecyclerView mRecyclerView;
RecyclerView.LayoutManager mLayoutManager;
PregnantAnimalAdapter mAdapter;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.PregnancyListLayout);
mRecyclerView = FindViewById<RecyclerView>(Resource.Id.recyclerView);
// Plug in the linear layout manager:
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.SetLayoutManager(mLayoutManager);
// Plug in my adapter:
mAdapter = new PregnantAnimalAdapter();
mAdapter.ItemClick += MAdapter_ItemClick;
mRecyclerView.SetAdapter(mAdapter);
}
}
Run Code Online (Sandbox Code Playgroud)
查看持有人
[Activity(Label = "PregnantAnimalViewHolder")]
public class PregnantAnimalViewHolder : RecyclerView.ViewHolder
{
public LinearLayout mBackground { get; private set; }
public …Run Code Online (Sandbox Code Playgroud) 我有一个对象列表,我试图通过两次迭代排序.
第一种是按对象中的整数字段按升序排序对象,即1-1000,然后按对象中的布尔字段按布尔值true和false排序.
我拥有的是......
public void updateAdapter()
{
List<Object> foobar = db.Get(ObjectID);
foobar = foobar.OrderBy(s => int.Parse(s.Tag)).ThenByDescending(s => s.Duplicate).ToList();
adapter = new ListAdapter(this, foobar);
RunOnUiThread(() => adapter.NotifyDataSetChanged());
ListView.Adapter = adapter;
}
Run Code Online (Sandbox Code Playgroud)
我的列表按整数字段n升序完美排序,但之后不按真值排序.我希望所有真值都按升序整数字段排序后转到对象列表的顶部.
样本输入:
Lists of Objects Inputted:
FooBar(11, false),
FooBar(1, false),
FooBar(54, true),
FooBar(34, true)
FooBar(77, false),
FooBar(33, false)
List of Objects Outputted:
FooBar(1, false),
FooBar(11, false),
FooBar(33, false),
FooBar(34, true),
FooBar(54, true),
FooBar(77, false),
Run Code Online (Sandbox Code Playgroud)
任何帮助都将是一个巨大的帮助.谢谢
我正在尝试将 PDFMaker 用于我的 Ionic 5 项目。1 先决条件是使用 Native File 和 FileOpener。当我尝试导入模块时,出现以下错误:
“FileOriginal”类型不能分配给“Provider”类型。
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { QRScanner } from '@ionic-native/qr-scanner/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { SideMenuComponent } from './components/side-menu/side-menu.component';
import { HttpClientModule, HttpClient } from …Run Code Online (Sandbox Code Playgroud)