我正在用C#.NET编写一个程序我想收集一个类的总频率(假设每个类有很多单词,每个单词在相应的类中都有自己的频率)
所以我在mysql中使用了sum()函数.但是有一个错误说我的演员是错的.
public void average_each_type()
{
MySqlDataReader result;
int total_freq = 0;
string type = "";
command.CommandText = "select class_name ,SUM(frequency) as sum_of_freq from training_set group by class_name ";
result = command.ExecuteReader();
while (result.Read())
{
total_freq = (int)result["sum_of_freq"]; //error happened here
type = result["class_name"].ToString();
//.....then so on...//
Run Code Online (Sandbox Code Playgroud) 我是片段新手并且有一个问题:当我更新我的SDK工具并创建一个项目(min = api8,默认值)时,我注意到我的Referenced Library中的android-support-v4.jar.
当我扩展我的类并尝试使用Fragment该类时,我发现有2个.一个是android.app.Fragment,另一个是android.support.v4.app.Fragment.这两者有什么区别?
我在tableRow中有一个linearLayout,这个linearLayout包含一个我想为我的应用程序显示的图表.我读了一些帖子说tableRow的子节点不需要指定它的宽度和高度,所以我做了,但是没有显示图表.如果我将linearLayout指定为width = fill_parent和height = 200dp,则linearlyLayout仅填充tableRow的1/3.
<?xml version="1.0" encoding="UTF-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Record"
android:textSize="18dp"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="Name:"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:ems="10"
android:singleLine="true" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="Date:"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="@+id/editRecordDate"
android:layout_width="0dp"
android:layout_weight="0.7"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="@+id/tableRow9" …Run Code Online (Sandbox Code Playgroud) 我想出如果我在中间运行AsyncTask时退出一个活动,当我再次尝试启动该活动时,我将不得不等到之前的AsyncTask在新的AsynTask启动之前完成.我尝试了thread.sleep和systemclock.sleep,它给了我相同的结果.这是有道理的,因为我猜我关闭和打开的线程是相同的.如果用户退出活动,它有一种方法可以取消AsyncTask吗?因为第二次用户输入相同的活动,他不必等到上一次完成.我在onPause()中尝试了asyntask.cancel(true),它不起作用,同样的事情发生了.
我在游标的帮助下从sqlite数据库中获取对象.我想将它们存储在一个arraylist中.问题是我不提前知道我返回数据的大小.那么如何将它们放入arraylist?
码:
public Student findAll()
{
db = helper.getWritableDatabase();
Cursor cursor = db.rawQuery("select sid, name, age from t_student", null
);
if(cursor.moveToNext())
return new Student(cursor.getInt(cursor.getColumnIndex("sid")), cursor.getString(cursor.getColumnIndex("name")), cursor.getInt(cursor.getColumnIndex("age")));
return null;
}
Main:
ArrayList<Student> studentArrayList = new ArrayList<Student>();
studentArrayList.add(dao.findAll()); //doing this will only return the first object from the database
Run Code Online (Sandbox Code Playgroud) 我有一个活动,使用清单中的dialog.theme,但我不希望当用户触摸对话框外时它被销毁.我做了一些搜索,发现setFinishOnTouchOutside(false)很有用,但它需要API11 android 3.0设备.我希望我的应用程序兼容旧版Android设备,解决方案是什么?
所以当我的表单加载时,它将连接到数据库,当我点击按钮时,它会在我的数据库中插入一个新行,但是在我点击它后我没有看到我的表中的任何更改.
namespace database
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection con;
private void Form1_Load(object sender, EventArgs e)
{
con = new SqlConnection();
con.ConnectionString =
"Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\myworkers.mdf;Integrated Security=True;User Instance=True";
con.Open();
MessageBox.Show("OPEN!");
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int x;
SqlCommand thiscommand = con.CreateCommand();
thiscommand.CommandText =
"INSERT INTO player_info (player_id, player_name) values (10, 'Alex') ";
x = thiscommand.ExecuteNonQuery(); /* I used variable x to verify …Run Code Online (Sandbox Code Playgroud) 我是Cstring的新手,很抱歉提出愚蠢的问题,请帮忙.
char string[10];
printf("Give me your last name:\n");
scanf ("%s", string); //if i type 123 123
printf("Original string:%s\n", string); //it shows 123
Run Code Online (Sandbox Code Playgroud)
相比于:
char string[] = "123 123";
printf("Original string:%s\n", string); //it shows 123 123
Run Code Online (Sandbox Code Playgroud) 如果我想打印出存储在"数组"中的整数,这确实是内存中的指针.当我使用代码时:
int main(void)
{
int *arr = malloc(3*sizeof(int));
int *p = arr;
*arr++=1;
*arr++=2;
*arr=3;
while (??) // what should be filled in the while?
printf("%d",*p); // so that we can get the validly stored elements?
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我的主要活动有这个代码.
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.startactivity);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
...
Run Code Online (Sandbox Code Playgroud)
但屏幕仍然在一段时间后暗淡,任何线索为什么会发生这种情况?