我正在尝试修改Tabs1.javaAndroid API演示16(并在API 16仿真器上运行)以使用标准Activity而不是已弃用的TabActivity类.我已经创建了一个新的布局文件并修改了代码.
我试图使用这种方法而不是操作栏的原因是标签不适用于整个屏幕,只适用于较小的子视图.
当我执行代码时,我在执行以下行时获得了NullPointerExceptionAndroid setContent方法内部:
tabHost.newTabSpec("tab1").setIndicator("tab1").setContent(R.id.view1)
任何想法为什么会这样?完整堆栈跟踪是在代码和布局之后.
Tabs1VanillaActivity.java:
public class Tabs1 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs1);
TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("tab1")
.setContent(R.id.view1));
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("tab2")
.setContent(R.id.view2));
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("tab3")
.setContent(R.id.view3));
}
}
Run Code Online (Sandbox Code Playgroud)
tabs1.xml:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView goes here!"
tools:ignore="HardcodedText" />
<TabHost
android:id="@+id/tabhost"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" …Run Code Online (Sandbox Code Playgroud) 我希望包含将图像文档扫描到我的应用程序中的功能.是否可以使用新的Google Drive API扫描图像文档?
我有一个关于Java中泛型的问题,即使用通配符.我有一个像这样的示例类GenClass:
public class GenClass<E> {
private E var;
public void setVar(E x) {
var = x;
}
public E getVar() {
return var;
}
}
Run Code Online (Sandbox Code Playgroud)
我有另一个简单的类:
public class ExampleClass {
}
Run Code Online (Sandbox Code Playgroud)
我写了以下测试类:
public class TestGenClass {
public static void main(String[] str) {
ExampleClass ec = new ExampleClass();
GenClass<ExampleClass> c = new GenClass<ExampleClass>();
c.setVar(ec);
System.out.println(c.getVar()); // OUTPUT: ExampleClass@addbf1
}
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我使用通配符并在测试类中写入:
GenClass<?> c = new GenClass<ExampleClass>();
Run Code Online (Sandbox Code Playgroud)
在以下的地方:
GenClass<ExampleClass> c = new GenClass<ExampleClass>();
Run Code Online (Sandbox Code Playgroud)
编译器对这个新语句没有任何问题,但它抱怨
c.setVar(ec);
Run Code Online (Sandbox Code Playgroud)
它说"方法(setVar())不适用于参数(ExampleClass)".为什么我收到此消息?
我认为我使用通配符的方式使得引用变量c的类型为GenClass,它将接受任何类作为参数 - 在EI的位置上将具有任何类.这只是变量的声明.然后我用它初始化它
new GenClass<ExampleClass>()
Run Code Online (Sandbox Code Playgroud)
这意味着我创建了一个GenClass类型的对象,它具有一个类型为ExampleClass的参数.所以,我认为现在GenClass中的E将是ExampleClass,我将能够使用方法setVar(),将其作为类型为ExampleClass的参数.这是我的假设和理解,但似乎Java不喜欢它,我不对.任何评论表示赞赏,谢谢.
我是否需要创建一个新模块,并将接口绑定到不同的实现?
Chef newChef = Guice.createInjector(Stage.DEVELOPMENT, new Module() {
@Override
public void configure(Binder binder) {
binder.bind(FortuneService.class).to(FortuneServiceImpl.class);
}
}).getInstance(Chef.class);
Chef newChef2 = Guice.createInjector(Stage.DEVELOPMENT, new Module() {
@Override
public void configure(Binder binder) {
binder.bind(FortuneService.class).to(FortuneServiceImpl2.class);
}
}).getInstance(Chef.class);
Run Code Online (Sandbox Code Playgroud)
我无法触及Chef Class和Interfaces.我只是一个客户端在运行时绑定到Chef的FortuneService到不同的接口.
java dependency-injection inversion-of-control guice robot-legs-problem
我正在将我的脚趾浸入Android开发中.我有一个项目将与RESTful资源接口,我试图弄清楚如何通过HTTP上的params进行基本GET.从我读过的所有内容来看,共识似乎都支持HTTPClient优于HttpURLConnection.
我编写了一个包装类,其中包含一个方法,该方法负责实例化密钥对象以使用HTTPClient发出请求:
public String get() {
String responseString = null;
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet();
try {
get.setURI(new URI(this.baseURL()));
} catch (URISyntaxException e1) {
e1.printStackTrace();
}
HttpResponse response;
try {
response = client.execute(get);
responseString = readResponse(response.getEntity());
if(response != null) {
System.out.println(responseString);
}
} catch(ClientProtocolException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}
return responseString;
Run Code Online (Sandbox Code Playgroud)
}
该行HttpClient client = new DefaultHttpClient();抛出以下异常:
java.lang.RuntimeException: Stub!
at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:5)
at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:7)
at org.rcindustries.appmap.RestClient.get(RestClient.java:54)
at org.rcindustries.appmap.test.functional.RestClientTest.shouldReturnSomeJSon(RestClientTest.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native …Run Code Online (Sandbox Code Playgroud) 我遇到的蛋糕模式的大多数示例似乎都将依赖关系视为单例类型服务; 在组件的最终组装中,每种类型只有一个实例.在使用Cake Pattern进行依赖注入时,是否可以编写具有多个特定类型实例的配置(可能以不同方式配置)?
请考虑以下组件.通用HTTP服务:
trait HttpService { def get(query:String):String }
trait HttpServiceComponent {
val httpService:HttpService
class HttpServiceImpl(address:String) extends HttpService {
def get(query:String):String = ...
}
}
Run Code Online (Sandbox Code Playgroud)
贸易和公司服务,每个服务都依赖于HttpService,它可能是不同的实例:
trait TradeService { def lastTrade(symbol:String):String }
trait TradeServiceComponent {
this:HttpServiceComponent => // Depends on HttpService
val tradeService:TradeService
class TradeServiceImpl extends TradeService {
def lastTrade(symbol:String):String =
httpService.get("symbol=" + symbol)
}
}
trait CompanyService { def getCompanySymbols(exchange:String):String }
trait CompanyServiceComponent {
this:HttpServiceComponent => // Depends on different HttpService instance
val companyService:CompanyService
class CompanyServiceImpl extends CompanyService …Run Code Online (Sandbox Code Playgroud) 我有一个带有ArrayAdapter的ListView,它包含一个带有Image和String的行.这工作正常,直到我决定图像的加载速度慢,所以我无法在显示列表之前加载图像.所以我开始使用一个单独的线程加载图像AsyncTask.
在我开始滚动列表之前,我对结果非常满意.加载了错误的图像,看起来这不是一段时间后图像的问题.如果我尝试对列表进行排序,则问题非常严重,并且没有任何图像位于右侧.
我做错了什么想法?
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ImageView imageView;
TextView textView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.drink_list_row, null);
}
Drink drink = allItems.get(position);
if (drink != null && v != null) {
imageView = (ImageView) v.findViewById(R.id.picture);
textView = (TextView) v.findViewById(R.id.drinkName);
imageView.setVisibility(View.GONE);
loadImageBitmap(drink, imageView);
textView.setText(drink.getName());
if (subItems != null && subItems.contains(drink)) {
textView.setVisibility(View.VISIBLE);
imageView.setVisibility(View.VISIBLE);
} else {
textView.setVisibility(View.GONE);
imageView.setVisibility(View.GONE);
}
}
return …Run Code Online (Sandbox Code Playgroud) android listview lazy-loading android-arrayadapter imageview
如何CountDownTimer访问onTick方法内的UI ?
(new CountDownTimer(10000,1000){
@Override
public void onFinish() {
// TODO Auto-generated method stub
}
@Override
public void onTick(long millisUntilFinished) {
TextView tv = (TextView)findViewById(R.id.tvLCD);
tv.setText(Long.toString(millisUntilFinished));
}
}).start();
Run Code Online (Sandbox Code Playgroud) 我想从SD卡播放音频文件.如何阅读音频文件并进行播放?下面是我播放音频文件的代码:
int sound1;
sound1 = mSoundPool.load(this, R.raw.om, 1);
mSoundPool.play(sound1, 1, 1, 1, time - 1, 1);
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我使用soundpool播放原始文件夹中的音频文件,但我需要使用soundpool播放sdcard中的音频文件.
现在有兴趣从SD卡播放音频.
如何实现这一目标?请帮助我尽快解决这个问题
我想使用Guava实现一个"peekable" ListIterator,它可以让我在不移动光标的情况下查看上一个和下一个列表元素.这类似于番石榴PeekingIterator,只是双向的,因为番石榴PeekingIterator只有一种next()方法,而不是一种方法previous().
这是否需要通过编写新PeekingListIterator类来实现,还是有一种Guava预期的方式来组合这两个概念?
android ×6
java ×4
android-file ×1
android-tabs ×1
collections ×1
generics ×1
guava ×1
guice ×1
httpclient ×1
imageview ×1
iterator ×1
layout ×1
lazy-loading ×1
list ×1
listview ×1
scala ×1
soundpool ×1
tabs ×1
unit-testing ×1