我正在尝试在下拉菜单中显示Micrsoft SQL Server数据库结果,但获得以下异常。
09-06 09:39:09.790 6710-6725/? E/ERRO﹕ Connection Established
09-06 09:39:09.875 6710-6725/? D/ERRO﹕ Result set executed
09-06 09:39:09.875 6710-6725/? D/Database Strings﹕ Ground
09-06 09:39:09.876 6710-6725/? I/Process﹕ Sending signal. PID: 6710 SIG: 9
09-06 09:39:09.888 5321-5727/? I/ActivityManager﹕ Process com.muchmore.www.dropdown (pid 6710) has died
09-06 09:39:09.899 5321-6064/? W/InputMethodManagerService﹕ Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@3962bb93 attribute=null, token = android.os.BinderProxy@2b0b1cb2
09-06 09:39:10.420 5635-5707/? W/OpenGLRenderer﹕ Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
09-06 09:39:12.898 5321-5385/? D/TaskPersister﹕ removeObsoleteFile: deleting file=41_task.xml
09-06 09:39:12.898 5321-5385/? D/TaskPersister﹕ removeObsoleteFile: deleting file=41_task_thumbnail.png
09-06 09:39:12.947 5321-5321/? D/BackupManagerService﹕ Received broadcast Intent { act=android.intent.action.PACKAGE_CHANGED dat=package:com.google.android.gms flg=0x4000010 (has extras) }
09-06 09:39:12.947 5321-5321/? I/BackupManagerService﹕ Unbinding ComponentInfo{com.google.android.gms/com.google.android.gms.backup.BackupTransportService}
09-06 09:39:12.951 5321-5354/? I/InputReader﹕ Reconfiguring input devices. changes=0x00000010
09-06 09:39:12.953 5321-5321/? I/BackupManagerService﹕ Binding to transport host ComponentInfo{com.google.android.gms/com.google.android.gms.backup.BackupTransportService}
09-06 09:39:12.963 5321-5321/? V/BackupManagerService﹕ Connected to transport ComponentInfo{com.google.android.gms/com.google.android.gms.backup.BackupTransportService}
09-06 09:39:12.964 5321-5321/? V/BackupManagerService﹕ Registering transport com.google.android.gms/.backup.BackupTransportService::com.google.android.gms/.backup.BackupTransportService = com.android.internal.backup.IBackupTransport$Stub$Proxy@28d42865
09-06 09:39:12.967 5549-5549/? W/GmsBackupAccountManager﹕ Backup account not found in gmscore.
09-06 09:39:12.980 5603-6729/? I/Backup﹕ [BackupTransportMigratorService] Starting migration...
09-06 09:39:12.981 5603-6729/? E/Backup﹕ [LegacyBackupAccountManager] Fail to get legacy transport context.
android.content.pm.PackageManager$NameNotFoundException: Application package com.google.android.backup not found
at android.app.ContextImpl.createPackageContextAsUser(ContextImpl.java:2139)
at android.app.ContextImpl.createPackageContext(ContextImpl.java:2115)
at android.content.ContextWrapper.createPackageContext(ContextWrapper.java:658)
at android.content.ContextWrapper.createPackageContext(ContextWrapper.java:658)
at com.google.android.gms.backup.as.<init>(SourceFile:47)
at com.google.android.gms.backup.BackupTransportMigratorService.b(SourceFile:146)
at com.google.android.gms.backup.BackupTransportMigratorService.onHandleIntent(SourceFile:81)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
09-06 09:39:12.981 5603-6729/? W/Backup﹕ [LegacyBackupAccountManager] No google accounts found!
09-06 09:39:12.986 5549-5562/? W/GmsBackupAccountManager﹕ Backup account not found in gmscore.
09-06 09:39:12.993 5603-6729/? I/Backup﹕ [BackupTransportMigratorService] Component name not found : com.google.android.backuptransport/com.google.android.backup.BackupTransportService
09-06 09:39:12.994 5603-6729/? I/Backup﹕ [BackupTransportMigratorService] Component name not found : com.google.android.backup/com.google.android.backup.BackupTransportService
09-06 09:39:12.994 5603-6729/? I/Backup﹕ [BackupTransportMigratorService] Successfully migrated to use GMS BackupTransportService!
09-06 09:39:13.004 5720-6731/? D/PackageBroadcastService﹕ Received broadcast action=android.intent.action.PACKAGE_CHANGED and uri=com.google.android.gms
09-06 09:39:13.007 5720-6731/? I/PackageBroadcastService﹕ Null package name or gms related package. Ignoreing.
09-06 09:39:13.022 5720-6048/? I/Icing﹕ updateResources: need to parse f{com.google.android.gms}
09-06 09:39:13.047 5549-5549/? V/GmsNetworkLocationProvi﹕ DISABLE
09-06 09:39:13.060 5549-5549/? I/GCoreNlp﹕ shouldConfirmNlp, NLP off. Ensuring opt-in disabled
我知道我应该使用Async而不是普通的线程,但这仅用于测试部分。稍后会改变这一点。但是这不起作用。出于安全考虑,我隐藏了凭据。
public class MainActivity extends AppCompatActivity {
String choosenItem = "nothing";
Connection connect;
PreparedStatement preparedStatement;
Statement st;
String[] list;
ArrayList<String> ArrayListing= null;
@SuppressLint("NewApi")
private Connection ConnectionHelper() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection connection = null;
String ConnectionURL = null;
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Log.e("ERRO", "Class Loaded");
ConnectionURL = "jdbc:jtds:sqlserver://localhost/college_portal;encrypt=fasle;user=cp;password=cp@23;instance=MSSQLSERVER;";
connection = DriverManager.getConnection(ConnectionURL);
Log.e("ERRO", "Connection Established");
} catch (SQLException se) {
Log.e("ERRO", se.getMessage());
} catch (ClassNotFoundException e) {
Log.e("ERRO", e.getMessage());
} catch (Exception e) {
Log.e("ERRO", e.getMessage());
}
return connection;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Runnable r = new Runnable() {
@Override
public void run() {
try {
connect = ConnectionHelper();
st = connect.createStatement();
ResultSet rs = st.executeQuery("select Items from drop_down");
Log.d("ERRO", "Result set executed");
Array z = null;
String s;
while(rs.next()){
s = rs.getString(1);
Log.d("Database Strings", s);
ArrayListing.add(s);
Log.d("Feeding array", "did it");
//z = rs.getArray("Items");
}
//list = (String[])z.getArray();
} catch (SQLException e) {
Log.e("ERRO", "Runnable Error");
e.printStackTrace();
}
}
};
Thread t = new Thread(r);
t.start();
Spinner dynamicSpinner = (Spinner) findViewById(R.id.dynamic_spinner);
String[] items = new String[] { "Chai Latte", "Green Tea", "Black Tea"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, ArrayListing);
dynamicSpinner.setAdapter(adapter);
dynamicSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
choosenItem = (String) parent.getItemAtPosition(position);
Log.v("item", choosenItem);
TextView show = (TextView) findViewById(R.id.selectedItem);
show.setText(choosenItem);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
}