我正在制作一个Twitter客户端作为学习Android的练习,并且登录和时间线活动工作正常,但当我点击Action Bar图标时,它会带我到ComposeTweetActivity.java
,然后我输入文本(我的推文)并按下推文按钮撰写推文,它没有做任何事情(它应该实际上传到我的Twitter帐户,然后返回我的TimelineActivity.java
)。在控制台中,它给出了错误:
04-14 18:10:34.797: E/SQLiteLog(998): (1) no such table: Users
04-14 18:10:34.805: E/SQLiteDatabase(998): android.database.sqlite.SQLiteException: no such table: Users (code 1): , while compiling: INSERT INTO Users(user_name,friends_count,profile_background_image_url,Tweet,user_id,screen_name,Id,tweet_count,profile_image_url,followers_count) VALUES (?,?,?,?,?,?,?,?,?,?)
加上许多其他错误。我的猜测是它必须对Active Android做一些事情,这是我用来保存的数据库。我有很多这个项目的文件,但我会发布ComposeTweetActivity.java
,因为它有撰写推文按钮(导致所有错误)和User.java
和Tweet.java
这些模型对于所有表数据的Active Android(我认为?),以及包含所有错误的控制台。如果您需要我发布更多文件,请高兴。非常感谢你的帮助。
ComposeTweetActivity.java
package com.codepath.apps.mytwitterapp;
import org.json.JSONObject;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.codepath.apps.mytwitterapp.models.Tweet;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.nostra13.universalimageloader.core.ImageLoader;
public class ComposeTweetActivity extends ActionBarActivity {
private Button btnCancel,
btnTweet;
private ImageView ivUserImage;
private TextView tvUserName;
private EditText etNewTweet;
private boolean alreadyToasted = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compose_tweet);
setupButtons();
setupImageView();
setupTextView();
setupEditText();
}
private void setupButtons() {
btnCancel = (Button) findViewById(R.id.btnCancel);
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent();
setResult(RESULT_CANCELED, i);
finish();
}
});
btnTweet = (Button) findViewById(R.id.btnTweet);
btnTweet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String tweetBody = etNewTweet.getText().toString();
tweet(tweetBody);
}
});
}
private void setupImageView() {
ivUserImage = (ImageView) findViewById(R.id.ivUserImage);
Log.d("DEBUG", "TimelineActivity.sScreenName is: " + TimelineActivity.getScreenName());
Log.d("DEBUG", "TimelineActivity.sImageUrl just before execution of "
+ "ImageLoader.getInstance().displayImage(mImageUrl, mIvUserImage) is: "
+ TimelineActivity.getUserImageUrl());
ImageLoader.getInstance().displayImage(TimelineActivity.getUserImageUrl(), ivUserImage);
}
private void setupTextView() {
tvUserName = (TextView) findViewById(R.id.tvUserName);
tvUserName.setText("@" + TimelineActivity.getScreenName());
}
private void setupEditText() {
etNewTweet = (EditText) findViewById(R.id.etNewTweet);
// Show soft keyboard when EditText field requests focus
if (etNewTweet.requestFocus()) {
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(etNewTweet, InputMethodManager.SHOW_IMPLICIT);
}
etNewTweet.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!alreadyToasted && s.length() == 140) {
Toast.makeText(ComposeTweetActivity.this, "You've reached the 140 character"
+ " limit", Toast.LENGTH_LONG).show();
alreadyToasted = true;
}
else if (s.length() > 140) {
etNewTweet.setTextColor(Color.RED);
} else {
etNewTweet.setTextColor(Color.BLACK);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
@Override
public void afterTextChanged(Editable s) { }
});
}
private void tweet(String tweetBody) {
MyTwitterApp.getRestClient().postTweet(tweetBody, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, JSONObject jsonTweetResponse) {
Log.d("DEBUG", "Called onSuccess() in tweet().");
Tweet newTweet = Tweet.fromJson(jsonTweetResponse);
new AsyncTweetSave().execute(newTweet);
Intent i = new Intent();
i.putExtra("new_tweet", newTweet);
setResult(RESULT_OK, i);
finish();
}
@Override
public void onFailure(Throwable e, JSONObject error) {
Log.d("DEBUG", "Called onFailure() in getUserScreenName(). Failure message: "
+ AsyncHttpResponseHandler.FAILURE_MESSAGE);
Log.e("ERROR", e.getMessage());
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.compose_tweet, menu);
return true;
}
}
User.java
package com.codepath.apps.mytwitterapp.models;
import java.io.Serializable;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;
import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
import com.codepath.apps.mytwitterapp.UserAccountSettings;
import com.codepath.apps.mytwitterapp.UserInfo;
/**
* Class acts as a Java-representation of a single user retrieved as a JSONObject from the
* Twitter REST API v1.1. Fields are as specified in the API Users object documentation.
*/
@Table(name = "Users")
public class User extends Model implements Serializable {
@Column(name = "user_name")
private String name;
@Column(name = "user_id", unique = true, onUniqueConflict = Column.ConflictAction.REPLACE)
private long userId; // User ID
@Column(name = "screen_name")
private String screenName;
@Column(name = "profile_image_url")
private String profileImageUrl;
@Column(name = "profile_background_image_url")
private String profileBackgroundImageUrl;
@Column(name = "tweet_count")
private int tweetCount; // Referred to as statuses_count in Twitter API
@Column(name = "followers_count")
private int followersCount;
@Column(name = "friends_count")
private int friendsCount;
@Column(name = "Tweet") // Created for ActiveAndroid to establish a direct
private Tweet tweet; // relationship with the Tweets table
public User() { // Empty-argument constructor required by ActiveAndroid
super();
}
public String getName() {
return name;
}
public long getUserId() {
return userId;
}
public String getScreenName() {
return screenName;
}
public String getProfileImageUrl() {
return profileImageUrl;
}
public String getProfileBackgroundImageUrl() {
return profileBackgroundImageUrl;
}
public int getNumTweets() {
return tweetCount;
}
public int getFollowersCount() {
return followersCount;
}
public int getFriendsCount() {
return friendsCount;
}
// Optional helper method for ActiveAndroid to establish a direct relationship with the
// UserAccountSettings table
public List<UserAccountSettings> getUserAccountSettings() {
return getMany(UserAccountSettings.class, "Users");
}
// Optional helper method for ActiveAndroid to establish a direct relationship with the
// UserInfo table
public List<UserInfo> getUserInfo() {
return getMany(UserInfo.class, "Users");
}
public static User fromJson(JSONObject jsonObject) {
User u = new User();
try {
u.name = jsonObject.getString("name");
u.userId = jsonObject.getLong("id");
u.screenName = jsonObject.getString("screen_name");
u.profileImageUrl = jsonObject.getString("profile_image_url");
u.profileBackgroundImageUrl = jsonObject.getString("profile_background_image_url");
u.tweetCount = jsonObject.getInt("statuses_count");
u.followersCount = jsonObject.getInt("followers_count");
u.friendsCount = jsonObject.getInt("friends_count");
} catch (JSONException e) {
e.printStackTrace();
}
return u;
}
}
Tweet.java
package com.codepath.apps.mytwitterapp.models;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
import com.activeandroid.ActiveAndroid;
import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
/**
* Class acts as a Java-representation of a single tweet retrieved as a JSONObject from the
* Twitter REST API v1.1. Fields are as specified in the API Tweets object documentation.
*/
@Table(name = "Tweets")
public class Tweet extends Model implements Serializable {
@Column(name = "max_id")
private static long maxId; // ID of the last (ie, earliest-timestamped) tweet to be processed in the current JSONArray
@Column(name = "tweet_id", unique = true, onUniqueConflict = Column.ConflictAction.REPLACE)
private long tweetId; // Tweet ID
@Column(name = "created_at")
private String createdAt;
@Column(name = "tweet_body")
private String body;
@Column(name = "favorited")
private boolean favorited;
@Column(name = "retweeted")
private boolean retweeted;
@Column(name = "user")
private User user;
public Tweet() { // Empty-argument constructor required by ActiveAndroid
super();
}
public static long getMaxId() {
return maxId;
}
public static String getMaxIdAsString() {
return String.valueOf(maxId);
}
public static void decrementMaxId() {
maxId -= 1;
}
public long getTweetId() {
return tweetId;
}
public String getCreatedAt() {
return createdAt;
}
public String getBody() {
return body;
}
public boolean isFavorited() {
return favorited;
}
public boolean isRetweeted() {
return retweeted;
}
public User getUser() {
return user;
}
// Optional helper method for ActiveAndroid to establish a direct relationship with the Users table
public List<User> getUsers() {
return getMany(User.class, "Tweets");
}
public static Tweet fromJson(JSONObject jsonObject) {
Tweet tweet = new Tweet();
try {
tweet.tweetId = jsonObject.getLong("id");
tweet.createdAt = jsonObject.getString("created_at");
tweet.body = jsonObject.getString("text");
tweet.favorited = jsonObject.getBoolean("favorited");
tweet.retweeted = jsonObject.getBoolean("retweeted");
tweet.user = User.fromJson(jsonObject.getJSONObject("user"));
} catch (JSONException e) {
e.printStackTrace();
return null;
}
return tweet;
}
public static ArrayList<Tweet> fromJson(JSONArray jsonArray) {
ArrayList<Tweet> tweets = new ArrayList<Tweet>(jsonArray.length());
for (int i=0; i < jsonArray.length(); i++) {
JSONObject tweetJson = null;
try {
tweetJson = jsonArray.getJSONObject(i);
} catch (Exception e) {
e.printStackTrace();
continue;
}
Tweet tweet = Tweet.fromJson(tweetJson);
if (tweet != null) {
maxId = tweet.getTweetId();
tweets.add(tweet);
}
}
return tweets;
}
public static void saveTweet(Tweet tweet) {
tweet.user.save();
tweet.save();
}
public static void saveTweets(ArrayList<Tweet> tweets) {
ActiveAndroid.beginTransaction();
try {
for (int i = 0; i < tweets.size(); i++) {
Tweet t = tweets.get(i);
Log.d("DEBUG", "Inside saveTweets(ArrayList<Tweet>), current tweet is: " + t.toString());
if (t != null) {
if (t.user != null) {
t.user.save();
}
t.save();
}
}
ActiveAndroid.setTransactionSuccessful();
} finally {
ActiveAndroid.endTransaction();
}
}
}
控制台充满了错误:
04-14 18:10:26.401: D/dalvikvm(998): GC_CONCURRENT freed 261K, 4% free 8611K/8967K, paused 10ms+1ms, total 16ms
04-14 18:10:26.745: D/dalvikvm(998): GC_CONCURRENT freed 353K, 5% free 8646K/9095K, paused 11ms+1ms, total 17ms
04-14 18:10:26.893: D/DEBUG(998): Called UserAccountSettings.fromJson(...). mScreenName is: noniazure
04-14 18:10:27.409: D/dalvikvm(998): GC_FOR_ALLOC freed 188K, 6% free 8683K/9159K, paused 2ms, total 3ms
04-14 18:10:27.409: D/dalvikvm(998): GC_FOR_ALLOC freed 140K, 7% free 8673K/9287K, paused 3ms, total 3ms
04-14 18:10:27.417: D/dalvikvm(998): GC_FOR_ALLOC freed 3K, 6% free 8790K/9287K, paused 4ms, total 4ms
04-14 18:10:27.417: I/dalvikvm-heap(998): Grow heap (frag case) to 8.726MB for 117780-byte allocation
04-14 18:10:27.417: D/dalvikvm(998): GC_FOR_ALLOC freed 182K, 8% free 8722K/9415K, paused 3ms, total 3ms
04-14 18:10:27.445: D/dalvikvm(998): GC_CONCURRENT freed 134K, 5% free 8972K/9415K, paused 11ms+1ms, total 14ms
04-14 18:10:27.473: D/OpenGLRenderer(998): TextureCache::get: create texture(0xb7d591e8): name, size, mSize = 92, 4, 1127492
04-14 18:10:27.493: D/dalvikvm(998): GC_CONCURRENT freed 332K, 5% free 9053K/9479K, paused 12ms+1ms, total 16ms
04-14 18:10:27.513: D/OpenGLRenderer(998): TextureCache::get: create texture(0xb7d9fc78): name, size, mSize = 95, 9216, 1136708
04-14 18:10:27.513: D/OpenGLRenderer(998): TextureCache::get: create texture(0xb7d9f130): name, size, mSize = 96, 9216, 1145924
04-14 18:10:27.525: D/OpenGLRenderer(998): TextureCache::get: create texture(0xb7d8b9c8): name, size, mSize = 98, 9216, 1155140
04-14 18:10:27.529: D/OpenGLRenderer(998): TextureCache::get: create texture(0xb7e2eb40): name, size, mSize = 99, 9216, 1164356
04-14 18:10:34.145: D/OpenGLRenderer(998): TextureCache::get: create texture(0xb7d68d78): name, size, mSize = 101, 324, 1164680
04-14 18:10:34.229: D/dalvikvm(998): GC_FOR_ALLOC freed 536K, 8% free 8745K/9479K, paused 3ms, total 3ms
04-14 18:10:34.237: I/dalvikvm-heap(998): Grow heap (frag case) to 9.449MB for 921612-byte allocation
04-14 18:10:34.249: D/dalvikvm(998): GC_CONCURRENT freed 4K, 8% free 9641K/10439K, paused 10ms+0ms, total 14ms
04-14 18:10:34.261: D/DEBUG(998): TimelineActivity.sScreenName is: noniazure
04-14 18:10:34.261: D/DEBUG(998): TimelineActivity.sImageUrl just before execution of ImageLoader.getInstance().displayImage(mImageUrl, mIvUserImage) is: null
04-14 18:10:34.297: W/EGL_emulation(998): eglSurfaceAttrib not implemented
04-14 18:10:34.313: D/OpenGLRenderer(998): TextureCache::get: create texture(0xb7d34e68): name, size, mSize = 104, 9216, 1173896
04-14 18:10:34.337: D/OpenGLRenderer(998): TextureCache::get: create texture(0xb7d64d60): name, size, mSize = 109, 100, 1173996
04-14 18:10:34.677: D/DEBUG(998): Inside saveTweets(ArrayList<Tweet>), current tweet is: Tweets@null
04-14 18:10:34.677: E/SQLiteLog(998): (1) no such table: Users
04-14 18:10:34.677: E/SQLiteDatabase(998): Error inserting user_name=Forbes Tech News friends_count=16449 profile_background_image_url=http://pbs.twimg.com/profile_background_images/92775085/twitter-background.jpg Tweet=null user_id=14885549 screen_name=ForbesTech Id=null tweet_count=41653 profile_image_url=http://pbs.twimg.com/profile_images/828527305/technology_normal.jpg followers_count=1154679
04-14 18:10:34.677: E/SQLiteDatabase(998): android.database.sqlite.SQLiteException: no such table: Users (code 1): , while compiling: INSERT INTO Users(user_name,friends_count,profile_background_image_url,Tweet,user_id,screen_name,Id,tweet_count,profile_image_url,followers_count) VALUES (?,?,?,?,?,?,?,?,?,?)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
04-14 18:10:34.677: E/SQLiteDatabase(998): at com.activeandroid.Model.save(Unknown Source)
04-14 18:10:34.677: E/SQLiteDatabase(998): at com.codepath.apps.mytwitterapp.models.Tweet.saveTweets(Tweet.java:137)
04-14 18:10:34.677: E/SQLiteDatabase(998): at com.codepath.apps.mytwitterapp.AsyncTweetsSave.doInBackground(AsyncTweetsSave.java:17)
04-14 18:10:34.677: E/SQLiteDatabase(998): at com.codepath.apps.mytwitterapp.AsyncTweetsSave.doInBackground(AsyncTweetsSave.java:1)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.lang.Thread.run(Thread.java:856)
04-14 18:10:34.677: E/SQLiteLog(998): (1) no such table: Tweets
04-14 18:10:34.677: E/SQLiteDatabase(998): Error inserting retweeted=false max_id=455761612532891649 favorited=false tweet_id=455769106550382593 created_at=Mon Apr 14 18:06:37 +0000 2014 tweet_body=CCP shuts down their in-development 'World of Darkness' MMO http://t.co/wZv6woImaZ Id=null user=-1
04-14 18:10:34.677: E/SQLiteDatabase(998): android.database.sqlite.SQLiteException: no such table: Tweets (code 1): , while compiling: INSERT INTO Tweets(retweeted,max_id,favorited,tweet_id,created_at,tweet_body,Id,user) VALUES (?,?,?,?,?,?,?,?)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
04-14 18:10:34.677: E/SQLiteDatabase(998): at com.activeandroid.Model.save(Unknown Source)
04-14 18:10:34.677: E/SQLiteDatabase(998): at com.codepath.apps.mytwitterapp.models.Tweet.saveTweets(Tweet.java:139)
04-14 18:10:34.677: E/SQLiteDatabase(998): at com.codepath.apps.mytwitterapp.AsyncTweetsSave.doInBackground(AsyncTweetsSave.java:17)
04-14 18:10:34.677: E/SQLiteDatabase(998): at com.codepath.apps.mytwitterapp.AsyncTweetsSave.doInBackground(AsyncTweetsSave.java:1)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.lang.Thread.run(Thread.java:856)
04-14 18:10:34.677: D/DEBUG(998): Inside saveTweets(ArrayList<Tweet>), current tweet is: Tweets@null
04-14 18:10:34.677: E/SQLiteLog(998): (1) no such table: Users
04-14 18:10:34.677: E/SQLiteDatabase(998): Error inserting user_name=Gizmodo friends_count=77 profile_background_image_url=http://pbs.twimg.com/profile_background_images/436934792/gizmodo-twitter-background-final.jpg Tweet=null user_id=2890961 screen_name=Gizmodo Id=null tweet_count=24648 profile_image_url=http://pbs.twimg.com/profile_images/1860214036/Gizmodo-Twitter-Avatar_normal.jpeg followers_count=887873
04-14 18:10:34.677: E/SQLiteDatabase(998): android.database.sqlite.SQLiteException: no such table: Users (code 1): , while compiling: INSERT INTO Users(user_name,friends_count,profile_background_image_url,Tweet,user_id,screen_name,Id,tweet_count,profile_image_url,followers_count) VALUES (?,?,?,?,?,?,?,?,?,?)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
04-14 18:10:34.677: E/SQLiteDatabase(998): at com.activeandroid.Model.save(Unknown Source)
04-14 18:10:34.677: E/SQLiteDatabase(998): at com.codepath.apps.mytwitterapp.models.Tweet.saveTweets(Tweet.java:137)
04-14 18:10:34.677: E/SQLiteDatabase(998): at com.codepath.apps.mytwitterapp.AsyncTweetsSave.doInBackground(AsyncTweetsSave.java:17)
04-14 18:10:34.677: E/SQLiteDatabase(998): at com.codepath.apps.mytwitterapp.AsyncTweetsSave.doInBackground(AsyncTweetsSave.java:1)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-14 18:10:34.677: E/SQLiteDatabase(998): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-14 18:10:34.677: E/SQLiteDatabase(998): at java.lang.Thread.run(Thread.java:856)
04-14 18:10:34.677: E/SQLiteLog(998): (1) no such table: Tweets
04-14 18:10:34.677: E/SQLiteDatabase(998): Error inserting retweeted=false max_id=455761612532891649 favorited=false tweet_id=455769104461594624 created_at=Mon Apr 14
..以及之前和之后......
ComposeTweetActivity的布局:
答案 0 :(得分:0)
善良,答案最终成为模拟器中的错误。事实证明,使用模型从Twitter API中绘制的Twitter客户端(我使用的是Active Android,但您也可以只使用原始的SQLite数据库表)...只会在未绘制表的情况下填充数据已经。因此,在我的情况下,进行大量更改并重新运行应用程序,意味着您要求重新填充并创建数据表,但它已经创建。
所以解决方案是在你的模拟器中卸载应用程序(或者只是使用一个新的模拟器)并重新运行程序!这将从头开始再次创建它,这是您的代码所要求的。它就像一个魅力。如此简单,却又如此棘手。 &GT; _&LT;
答案 1 :(得分:-1)
你可以用我的方法测试 添加到AndroidManifest.xml:
<meta-data android:name="AA_MODELS" android:value="com.codepath.apps.mytwitterapp.models.User, com.codepath.apps.mytwitterapp.models.Tweet" />