如果我要向List中添加未知数量的元素,并且该列表只会被迭代,那么LinkedList会比特定实例中的ArrayList更好(使用Java,如果它有任何相关性)
使用维基百科(http://en.wikipedia.org/wiki/Decorator_pattern)上显示的咖啡装饰器示例,如何能够拥有只有装饰者拥有的方法,例如,牛奶装饰者可能拥有的方法一个名为"fatContent"的方法.这种设计模式是否可以实现这一点?如果没有,我可以使用什么样的模式来实现这一目标?
由于此 RuntimeException,我的应用程序无法启动:
java.lang.RuntimeException: Unable to get provider org.worldsproject.android.barcode.database.DatabaseProvider: java.lang.ClassNotFoundException: org.worldsproject.android.barcode.database.DatabaseProvider
Run Code Online (Sandbox Code Playgroud)
我的清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.worldsproject.android.barcode"
android:versionCode="4"
android:versionName="1.0.3" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock" >
<activity
android:name="BarcodeSaleTracker"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider android:name="org.worldsproject.android.barcode.database.DatabaseProvider"
android:multiprocess="true"
android:exported="false"
android:authorities="org.worldsproject.android.barcode.database.DatabaseProvider" />
</application>
Run Code Online (Sandbox Code Playgroud)
我的数据库提供者:
package org.worldsproject.android.barcode.database;
public class DatabaseProvider extends ContentProvider{
private static final String TAG = "DatabaseProvider";
private static final String DATABASE_NAME = "sales.db";
private static final int DATABASE_VERSION = 1;
public static final String AUTHORITY …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现Twitter Bootstrap轮播,到目前为止我一直没有成功.我有以下页面:
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset="utf-8">
<title>Fluxware: Play, learn and build games</title>
<meta name="description" content="Home page for Fluxware">
<meta name="author" content="Tim Butram">
<!-- CSS Stylesheets -->
<link href="../bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="../bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<!--For shitty webbrowsers -->
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/sbn/trunk/html5.js></script>
<![endif]-->
<!-- Favicon -->
<link rel="favicon" href="images/favicon.ico">
</head>
<body>
<!-- Navbar -->
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Play</a></li>
<li><a href="#">Learn</a></li>
<li><a href="#">Build</a></li>
</ul>
</div>
</div>
</div> …Run Code Online (Sandbox Code Playgroud) 我有一个SQLiteDatabase,其数据由Content Provider管理.我正在使用标签式布局.第一个选项卡具有向数据库添加行的功能,而第二个选项卡显示数据库中的项目.当我从第一个选项卡向数据库添加项目时,当我移动到另一个选项卡时,应该反映更改.
数据正在正确地添加到数据库中,并且在首次打开应用程序时,将显示所有当前数据(以及在应用程序的先前版本中添加的任何新内容).但是,在ListFragment中不会反映向数据库中添加新项目.
@Override
public void onClick(View v) {
if(v == addSale) {
Item item = new Item(rn(), null, 100);
data.add(item);
total += item.getAmount();
} else if(v == save) {
for(Item i: data) {
ContentValues cv = new ContentValues();
cv.put(DatabaseProvider.COLUMN_COST, i.getAmount());
cv.put(DatabaseProvider.COLUMN_ITEM, i.getItem());
cv.put(DatabaseProvider.COLUMN_PERSON, i.getPerson());
this.getActivity().getContentResolver().insert(DatabaseProvider.CONTENT_URI, cv);
}
total = 0;
data.clear();
} else if(v == clear) {
data.clear();
total = 0;
}
items.notifyDataSetChanged();
totalView.setText(Item.format(total));
}
Run Code Online (Sandbox Code Playgroud)
这是我将这些项目添加到数据库的具体位置:
ContentValues cv = new ContentValues();
cv.put(DatabaseProvider.COLUMN_COST, i.getAmount());
cv.put(DatabaseProvider.COLUMN_ITEM, i.getItem());
cv.put(DatabaseProvider.COLUMN_PERSON, i.getPerson()); …Run Code Online (Sandbox Code Playgroud) 我有一个文件queue.c,用C语言定义一个队列.我如何使3个独立的队列相互独立?我对C不是很有经验,我一直在OO视图中考虑它,而且我知道我不能这样做.
#include <stdio.h>
#include <stdlib.h>
struct Node
{
char data;
struct Node *next;
} *Head, *Tail;
void addCharacter(char c)
{
struct Node *temp1, *temp2;
temp1 = (struct Node *)malloc(sizeof(struct Node));
temp1->data = c;
temp2 = Tail;
if(Head == NULL)
{
Head = temp1;
Head->next = NULL;
Tail = Head;
}
else
{
Tail = temp1;
temp1->next = NULL;
temp2->next = temp1;
}
}
void deleteCharacter()
{
struct Node *temp1 = Head;
Head = temp1->next;
free(temp1);
}
int replaceCharacter(char c)
{ …Run Code Online (Sandbox Code Playgroud) 所以,我有一个很好的小视图,我已经制作了,它基本上显示了两个带有一些状态标签的按钮.没有什么太复杂的.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ToggleButton android:text="ToggleButton" android:id="@+id/toggleButton1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/on_off">
</ToggleButton>
<TextView android:text="TextView" android:id="@+id/textView1"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginLeft="20px" android:layout_marginRight="20px"
android:layout_marginTop="3dp" android:layout_marginBottom="3dp">
</TextView>
<ImageButton android:src="@drawable/preferences"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="@+id/imageButton2" android:background="@android:color/transparent">
</ImageButton>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:id="@+id/view_monday" android:textSize="10dp" android:layout_marginRight="3dp"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#2F4F4F"
android:text="@string/monday_short"></TextView>
<TextView android:id="@+id/view_tuesday" android:textSize="10dp" android:layout_marginRight="3dp"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#2F4F4F"
android:text="@string/tuesday_short"></TextView>
<TextView android:id="@+id/view_wednesday" android:textSize="10dp" android:layout_marginRight="3dp"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#2F4F4F"
android:text="@string/wednesday_short"></TextView>
<TextView android:id="@+id/view_thursday" android:textSize="10dp" android:layout_marginRight="3dp"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#2F4F4F"
android:text="@string/thursday_short"></TextView>
<TextView android:id="@+id/view_friday" android:textSize="10dp" android:layout_marginRight="3dp"
android:layout_height="wrap_content" …Run Code Online (Sandbox Code Playgroud) 我无法成功运行着色器,我似乎错过了一些让它全部工作的步骤.我最终得到的错误是:
Exception in thread "main" org.lwjgl.opengl.OpenGLException: Invalid operation (1282)
at org.lwjgl.opengl.Util.checkGLError(Util.java:59)
at org.lwjgl.opengl.GL20.glUniform1i(GL20.java:374)
at sprites.Sprite.draw(Sprite.java:256)
at gui.Game.drawFrame(Game.java:238)
at gui.Game.gameLoop(Game.java:205)
at gui.Game.startGame(Game.java:244)
at tests.simple.SimpleShader.main(SimpleShader.java:36)
Run Code Online (Sandbox Code Playgroud)
我的初始化开始于:
int frag = FilterLoader.createShader("/tests/resources/shaders/grayscale.frag", GL20.GL_FRAGMENT_SHADER);
Run Code Online (Sandbox Code Playgroud)
并且createShader方法如下所示:
int shader = GL20.glCreateShader(type);
if(shader == 0)
return 0;
StringBuilder code = new StringBuilder("");
String line;
try
{
String path = FilterLoader.class.getResource(filename).getPath();
BufferedReader reader = new BufferedReader(new FileReader(path));
while((line = reader.readLine()) != null)
{
code.append(line + "\n");
}
}
catch(Exception e)
{
e.printStackTrace();
System.err.println("Error reading in " + type + …Run Code Online (Sandbox Code Playgroud) 所以我有一些看起来如下的html:
<div class='something unknown' id='something_unknown_1'>
<button onClick='removeParent(self)'>Remove me and my parent div</div>
</div>
<div class='something unknown' id='something_unknown_2'>
<button onClick='removeParent(self)'>Remove me and my parent div</div>
</div>
Run Code Online (Sandbox Code Playgroud)
...等等.如何在不知道按钮ID的情况下引用触发onClick的按钮?我想最终让我的removeParent(self)方法看起来像:
buttonThatWasClicked.parent().remove();
Run Code Online (Sandbox Code Playgroud) public static void main(String args[])
{
Random r = new Random();
BufferedImage buf = new BufferedImage(500, 500, BufferedImage.TYPE_3BYTE_BGR);
Point[] points = new Point[50];
for(int i = 0; i < points.length; i++)
{
points[i] = new Point(r.nextInt(500), r.nextInt(500));
}
int b = Color.BLUE.getRGB();
int w = Color.WHITE.getRGB();
int g = Color.GREEN.getRGB();
for(int i = 0; i < points.length; i++)
{
buf.setRGB(points[i].x, points[i].y, b);
}
Point close = null;
int max = 5000;
for(int k = 0; k < points.length; k++)
{ …Run Code Online (Sandbox Code Playgroud)