04-24 12:15:21.671: E/AndroidRuntime(26419):java.lang.RuntimeException: Unable to start activity ComponentInfo{com.flocator/com.flocater.Friendfinderactivity}:android.database.sqlite.SQLiteException: near "null": syntax error(code 1): , while compiling: select * from null
这是我每次尝试编译时都会遇到的错误..我是一个学习机器人,所以我对此不太了解...所以任何人都可以帮我解决这个问题..
我也收到错误Source not found
你能帮我解决这两个问题。
代码在Friendfnderactivity.java
package com.flocater;
import com.flocator.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class Friendfinderactivity extends Activity {
/** Called when the activity is first created. */
public static String deviceid = "deviceid";
public static String device_id = "device_id";
public static String user_id = "user_id";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DBHelper dbhelper = new DBHelper(this);
SQLiteDatabase db = dbhelper.getWritableDatabase();
TelephonyManager tm = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
deviceid = tm.getDeviceId();
Cursor cursor = db.rawQuery("select * from "
+ Database.SUBSCRIBE_TABLE_NAME, null);
int rows = cursor.getCount();
if (rows > 0) {
cursor.moveToFirst();
user_id = cursor.getString(0);
device_id = cursor.getString(3);
}
db.close();
if (device_id.equals(deviceid)) {
setContentView(R.layout.subscriber);
} else
setContentView(R.layout.subscribe);
}
public void subscribeUser(View v) {
// get access to views
EditText editName = (EditText) this.findViewById(R.id.editName);
EditText editPhone = (EditText) this.findViewById(R.id.editPhone);
EditText editArea = (EditText) this.findViewById(R.id.editArea);
EditText editCity = (EditText) this.findViewById(R.id.editCity);
boolean done = Database.addUser(this, editName.getText().toString(),
editPhone.getText().toString(), deviceid, editArea.getText()
.toString(), editCity.getText().toString());
if(done) {
Toast.makeText(this, "Subscribed Successfully!", Toast.Length_Long).show();
Intent intent = new Intent(this,Friendfinderactivity.class);
startActivity(intent);
}
else
Toast.makeText(this, "Sorry! Could not subscribe!", Toast.LENGTH_LONG).show();
}
public void addFriends(View v) {
Intent intent = new Intent(this,AddFriends.class);
startActivity(intent);
}
public void viewFriends(View v) {
Intent intent = new Intent(this,SeeFriends.class);
startActivity(intent);
}
}
答案 0 :(得分:0)
错误很明显"select * from null"
这是您的SQL查询
此处表名为null。
您只需添加表名即可。 例如 用
替换以下行Cursor cursor = db.rawQuery("select * from "
+ Database.SUBSCRIBE_TABLE_NAME, null);
此
Cursor cursor = db.rawQuery("select * from your_table_name", null);
我只是告诉您根据需要修改的错误。