TCP サーバーに接続しようとしているときにアプリがフリーズする理由がわかりません。接続すると他のメッセンジャーからサインオフするため、接続を確立しますが、「ログイン中..」と表示されるとフリーズします。
07-01 05:37:55.297: E/AndroidRuntime(280): FATAL EXCEPTION: main
07-01 05:37:55.297: E/AndroidRuntime(280): java.lang.RuntimeException: Unable to get provider com.android.providers.contacts.CallLogProvider: java.lang.IllegalStateException: error upgrading the database to version 309
07-01 05:37:55.297: E/AndroidRuntime(280): at android.app.ActivityThread.installProvider(ActivityThread.java:4509)
07-01 05:37:55.297: E/AndroidRuntime(280): at android.app.ActivityThread.installContentProviders(ActivityThread.java:4281)
07-01 05:37:55.297: E/AndroidRuntime(280): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4237)
07-01 05:37:55.297: E/AndroidRuntime(280): at android.app.ActivityThread.access$3000(ActivityThread.java:125)
07-01 05:37:55.297: E/AndroidRuntime(280): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
07-01 05:37:55.297: E/AndroidRuntime(280): at android.os.Handler.dispatchMessage(Handler.java:99)
07-01 05:37:55.297: E/AndroidRuntime(280): at android.os.Looper.loop(Looper.java:123)
07-01 05:37:55.297: E/AndroidRuntime(280): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-01 05:37:55.297: E/AndroidRuntime(280): at java.lang.reflect.Method.invokeNative(Native Method)
07-01 05:37:55.297: E/AndroidRuntime(280): at java.lang.reflect.Method.invoke(Method.java:521)
07-01 05:37:55.297: E/AndroidRuntime(280): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-01 05:37:55.297: E/AndroidRuntime(280): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-01 05:37:55.297: E/AndroidRuntime(280): at dalvik.system.NativeStart.main(Native Method)
07-01 05:37:55.297: E/AndroidRuntime(280): Caused by: java.lang.IllegalStateException: error upgrading the database to version 309
07-01 05:37:55.297: E/AndroidRuntime(280): at com.android.providers.contacts.ContactsDatabaseHelper.onUpgrade(ContactsDatabaseHelper.java:1507)
07-01 05:37:55.297: E/AndroidRuntime(280): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:108)
07-01 05:37:55.297: E/AndroidRuntime(280): at com.android.providers.contacts.ContactsDatabaseHelper.getWritableDatabase(ContactsDatabaseHelper.java:2507)
07-01 05:37:55.297: E/AndroidRuntime(280): at com.android.providers.contacts.CallLogProvider.onCreate(CallLogProvider.java:79)
07-01 05:37:55.297: E/AndroidRuntime(280): at android.content.ContentProvider.attachInfo(ContentProvider.java:733)
07-01 05:37:55.297: E/AndroidRuntime(280): at android.app.ActivityThread.installProvider(ActivityThread.java:4506)
07-01 05:37:55.297: E/AndroidRuntime(280): ... 12 more
07-01 05:37:55.328: W/ActivityManager(59): Process android.process.acore has crashed too many times: killing!
07-01 05:37:55.328: W/ActivityManager(59): Unable to launch app com.android.providers.contacts/10009 for provider call_log: launching app became null
07-01 05:37:55.328: E/ActivityThread(114): Failed to find provider info for call_log
問題を突き止めようとしてこれらのログを調べましたが、まだ何もうまくいきませんでした...アプリがフリーズしている原因は何ですか?
編集:
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
public class Connectionn extends Thread implements XfireObserver {
private DataInputStream in = null;
private DataOutputStream out = null;
private byte[] buffer;
private String username, password, nickname, statustext = "Online";
private boolean runThread = true;
public Connectionn() {
EventManager.addObserver(this);
}
/**
* Connect to Xfire using the username and password provided in the constructor.
*/
public void connect(String username, String password) {
this.username = username;
this.password = password;
try {
if (!runThread)
return;
Socket s = new Socket("cs.xfire.com", 25999);
in = new DataInputStream(s.getInputStream());
out = new DataOutputStream(s.getOutputStream());
login();
} catch (Exception e) {
e.printStackTrace();
disconnect();
}
}
public void disconnect() {
EventManager.removeObserver(this);
runThread = false;
try {
out.write(new byte[] { 0, 0, 0, 0 }); // sabotage the stream
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
out.close();
in.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
FriendManager.getInstance().cleanup();
EventManager.fireEvent(new DatalessEvent(XfireEvent.XF_OFFLINE));
}
}
public void run() {
setName("Xfire Reader Thread");
while(runThread) {
readBytes();
debug(buffer);
switch(buffer[0] & 0xFF) {
case 0x80: // salt
SaltPacket sp = new SaltPacket(buffer);
LoginPacket lp = new LoginPacket(username, password, sp.getSalt());
write(lp.getBytes());
break;
case 0x81: // auth failed
disconnect();
EventManager.fireEvent(new DatalessEvent(XfireEvent.XF_LOGINFAIL));
break;
case 0x82: // loginreply
LoginReplyPacket lrp = new LoginReplyPacket(buffer);
nickname = lrp.getNickname();
break;
case 0x83: // friendslist
new FriendslistPacket(buffer);
break;
case 0x84: // friend online
new FriendStatusPacket(buffer);
break;
case 0x85: // receive message
ReceiveMessagePacket rmp = new ReceiveMessagePacket(buffer);
if (rmp.getMessageType() == ReceiveMessagePacket.MSGTYPE_IM) {
AckImPacket amp =
new AckImPacket(rmp.getSid(), rmp.getImIndex());
write(amp.getBytes());
}
break;
case 0x87: // friend in game
new FriendGamePacket(buffer);
break;
case 0x91: // disconnected with reason
disconnect();
EventManager.fireEvent(new DatalessEvent(XfireEvent.XF_DCREASON));
break;
case 0x9a: // friend status text
new FriendStatusTextPacket(buffer);
break;
case 0xac:
new ScreenshotsPacket(buffer);
break;
}
}
}
private void login() {
// initialize connection with the 'UA01' packet
write("UA01".getBytes());
System.out.println("asd");
// send the version packet
VersionPacket vp = new VersionPacket();
write(vp.getBytes());
// start the reader thread
try{
start();
}catch(Exception threade){
System.out.println("Thread was not called!");
}
}
/**
* Returns the nickname set for this Xfire user.
* @return the current nickname.
*/
public String getNickname() {
return nickname;
}
/**
* Sets a new nickname for this Xfire user.
* @param nick the nickname to set.
*/
public void setNickname(String nickname) {
ChangeNickPacket cnp = new ChangeNickPacket(nickname);
write(cnp.getBytes());
this.nickname = nickname;
}
public String getStatusText() {
return statustext;
}
public void setStatusText(String statustext) {
ChangeStatusTextPacket cstp = new ChangeStatusTextPacket(statustext);
write(cstp.getBytes());
this.statustext = statustext;
}
public String getUsername() {
return username;
}
public void handleEvent(XfireEvent event) {
switch(event.getEventType()) {
case XfireEvent.XF_SENDIM:
SendImEvent e = (SendImEvent)event;
SendImPacket sip = new SendImPacket(e.getSid(), e.getImindex(),
e.getMessage());
write(sip.getBytes());
return;
case XfireEvent.XF_REQINFO:
Friend f = ((FriendEvent)event).getFriend();
RequestInfoPacket rip = new RequestInfoPacket(f.getUserid());
write(rip.getBytes());
return;
}
}
/*
* I/O and debugging methods
*/
private void readBytes() {
try {
byte[] numBytes = new byte[2];
in.read(numBytes, 0, 2);
int low = numBytes[0] & 0xFF, high = numBytes[1] & 0xFF;
int len = (0x00 | low | (high << 8)) - 2;
if (len <= 0) {
buffer = new byte[] { 0 };
return;
}
buffer = new byte[len];
in.read(buffer, 0, len);
} catch (IOException ioe) {
ioe.printStackTrace();
disconnect();
}
}
public void write(byte[] bs) {
try {
out.write(bs);
} catch (IOException ioe) {
ioe.printStackTrace();
disconnect();
}
}
private static void debug(byte[] bs) {
for (byte b : bs) {
System.out.print(String.format("%02x", b) + " ");
}
System.out.println();
}
}