是否有一个"最佳实践",可以在try/catch块中放入多少代码?
我在下面发布了3种不同的场景.
我没有在每个catch块中包含行为,我没有包含finally块.这是为了提高观众的可读性.假设每个人都catch做了不同的事情.并假设finally将关闭流.试着为未来的读者创建一个易于阅读的例子.
try/catch.try/catch为每个需要的地方1 .try/catch周围的整个代码块.什么被普遍认为是最佳实践,为什么?
场景1
代码没有try/catch,只是为了控制.
BufferedReader bufferedReader = new BufferedReader(new FileReader("somepath"));
String line;
while ((line = bufferedReader.readLine()) != null) {
Object object = new Object();
this.doSomething(object);
}
bufferedReader.close();
Run Code Online (Sandbox Code Playgroud)
情景2
代码,try/catch每个地方都需要一个块.
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader("somepath"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String line;
try {
while ((line = bufferedReader.readLine()) != …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个类似按钮的组件,左侧对齐的ImageView,然后是ImageView右侧的2个TextView,一个堆叠在另一个之上,格式不同,如下例所示:
__________________________
| |
| |-----| Bold Main Text |
| |Image| |
| |-----| Small Sub Text |
|__________________________|
Run Code Online (Sandbox Code Playgroud)
我还希望ImageView根据外部容器的单击状态进行更改,就像标准按钮可以使用与之关联的可选资源一样.因此,当我单击外框中的任何位置时,图像可选状态会发生变化.
我知道我可以使用Button,设置'drawableLeft'属性来创建与Image相关联的单行文本作为按钮,但似乎我只能使用此策略的单个文本项.
有没有人在过去实现过这样的UI组件?
谢谢!
我有一个edittext和一个按钮在我的布局,并在我的代码我设置keyListener了的edittext为空
editText.setKeyListener(null);
Run Code Online (Sandbox Code Playgroud)
所以我不能输入我的edittext.现在点击我的按钮,我应该可以输入我的ediitext.我怎样才能做到这一点.这是一个简单的问题,但我无法找到任何解决方案.任何帮助将非常感激.
我想设计一个Android应用程序,它可以帮助学生和其他人在特定建筑物(一层楼)中导航,显示走向教室的步行路线.
我需要帮助.
如何将外部库和嵌套外部库添加到android项目?
我的项目结构(不允许更改)
应用1 /的build.gradle
buildscript {
...
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':..:libraries:library1')
compile project(':..:libraries:library2')
compile project(':..:libraries:library3')
compile project(':..:libraries:library4')
}
android {
...
}
Run Code Online (Sandbox Code Playgroud)
APP1并不直接依赖于library3或library4,但是,它会抱怨,如果我不包括他们在在依赖build.gradle文件和settings.gradle文件.所以,我把它们包括在内只是为了阻止它抱怨.
应用1/settings.gradle
include ':'
include '..:libraries:library1'
include '..:libraries:library2'
include '..:libraries:library3'
include '..:libraries:library4'
Run Code Online (Sandbox Code Playgroud)
LIBRARY1 /的build.gradle
buildscript {
... …Run Code Online (Sandbox Code Playgroud) 我想OAuthComponent在我的GettingStartedPage组件中显示一个.在OAuthComponent当提供给我的浏览器没有显示出来.没有错误.
OAuthComponent.ts
import {Page, NavController} from 'ionic/ionic';
import {Component} from 'angular2/angular2'
@Component({
templateUrl: "app/authentication/components/oauth-component.html",
selector: "oauth-component"
})
export class OAuthComponent {
private nav: NavController;
constructor(nav: NavController) {
this.nav = nav;
}
}
Run Code Online (Sandbox Code Playgroud)
oauth-component.html
<h1>
Testing Something
</h1>
Run Code Online (Sandbox Code Playgroud)
GettingStartedPage.ts
import {Page, NavController} from 'ionic/ionic';
import {OAuthComponent} from "../authentication/components/OAuthComponent";
import "./getting-started.scss";
@Page({
templateUrl: 'app/getting-started/getting-started.html',
directives: [OAuthComponent]
})
export class GettingStartedPage {
private nav: NavController;
constructor(nav: NavController) {
this.nav = nav;
}
}
Run Code Online (Sandbox Code Playgroud)
getting-started.html
<ion-navbar *navbar>
<a …Run Code Online (Sandbox Code Playgroud) 我是Android的新手,并尝试做一个示例应用程序,其中3个元素(2个按钮和1个文本视图)水平放置.我需要文本位于中心,两个按钮在视图的左右对齐.
例如
|<Button> <Text> <Button>|
Run Code Online (Sandbox Code Playgroud)
感谢您是否可以帮助我.
提前致谢
我正在尝试设置位于我的src文件夹中的资源文件夹中的图像的URL.始终将URL设置为null.图像在那里,一切都被正确命名.有什么问题?谢谢!
我的文件结构:
这是我的代码,我试图设置图片的URL:
this.setImagePath(getClass().getResource("/resources/01.png"));
Run Code Online (Sandbox Code Playgroud)
并且setImagePath正在执行此操作,我确信这不是问题,因为我遵循执行并且将其设置为等于null.
public final void setImagePath(URL imagePath) {
this.imagePath = imagePath;
}
Run Code Online (Sandbox Code Playgroud)
解
我不得不清理构建并重建.它在修复之后起作用了.
谢谢
我想要一个可以存储我的应用程序中使用的所有字符串的地方,所以我可以在一个地方而不是所有地方修改它们.像资源文件,我可以在字符串上放置标签,只需调用标签.
我不知道QT为此提供了什么,所以我只需要创建一个包含所有字符串的头文件并将其包含在我需要的任何地方吗?这样做的适当方法是什么,你能提供一个小例子吗?
谢谢!!
我有屏幕ScrollView和三个不同LinearLayouts.
一个LinearLayout包含a Spinner和第二个包含ListView,第三个包含两个Buttons(水平).
我想显示一个屏幕,其中包含3个LinearLayouts始终显示在屏幕底部,1个屏幕LinearLayout始终显示在顶部.在中间部分,我想显示ListView内容.因此,在整个屏幕上没有空白空间.
我想为具有不同尺寸的多个设备创建屏幕.
<?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:background="@drawable/backrepeat"
android:orientation="vertical" >
<include
android:id="@+id/include1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/actionbar" >
</include>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".2"
android:background="@drawable/rounded_border"
android:orientation="vertical"
android:padding="15dp" >
<TextView
android:id="@+id/tvDiaryData"
style="@style/greenstyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/heading"
android:gravity="center_horizontal"
android:text="@string/tvDiaryData" >
</TextView>
<TextView
android:layout_width="fill_parent"
android:layout_height="10dp"
android:gravity="center_horizontal" >
</TextView>
<Spinner
android:id="@+id/spDiaryAllBooking"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/select_diaryallbooking" /> …Run Code Online (Sandbox Code Playgroud) android android-widget android-emulator android-intent android-layout