点击config.json
中的var pg = require('pg')
,q = require('q')
,config = require('custom-modules/config.json')
conString = 'postgres://'+ config.pg.admun +':' + config.pg.admpw + '@' + config.pg.host + ':' + config.pg.port + '/' + config.pg.defdb;
function runSQL (sqlStatement) {
var deferred = q.defer();
var results = [];
// Get a Postgres client from the connection pool
pg.connect(conString, function(err, client, done) {
// SQL Query > Select Data
var query = client.query(sqlStatement, function(err, res) {
if(err) console.log(err);
deferred.resolve(res);
});
// After all data is returned, close connection and return results
query.on('end', function() {
client.end();
deferred.resolve(results);
});
// Handle Errors
if(err) {
console.log(err);
}
});
return deferred.promise;
};
,我试图从runSQL("SELECT * FROM tablename").then(function(res) {
// here you have access to the result of the query... with "res".
console.log(res);
});
跳到MainActivity.java
。我得到了这样的LogCat:
ToDoList.java
我的MainActivity.java中的代码是这样的:
button01
我的清单是这样的:
activity_main.xml
按钮的代码是:
07-06 00:50:04.487: W/dalvikvm(779): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-06 00:50:04.516: E/AndroidRuntime(779): FATAL EXCEPTION: main
07-06 00:50:04.516: E/AndroidRuntime(779): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.splashscreen.ToDoList }
07-06 00:50:04.516: E/AndroidRuntime(779): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
07-06 00:50:04.516: E/AndroidRuntime(779): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
07-06 00:50:04.516: E/AndroidRuntime(779): at android.app.Activity.startActivityForResult(Activity.java:3370)
07-06 00:50:04.516: E/AndroidRuntime(779): at android.app.Activity.startActivityForResult(Activity.java:3331)
07-06 00:50:04.516: E/AndroidRuntime(779): at android.app.Activity.startActivity(Activity.java:3566)
07-06 00:50:04.516: E/AndroidRuntime(779): at android.app.Activity.startActivity(Activity.java:3534)
07-06 00:50:04.516: E/AndroidRuntime(779): at com.example.splashscreen.MainActivity.button1Click(MainActivity.java:39)
07-06 00:50:04.516: E/AndroidRuntime(779): at com.example.splashscreen.MainActivity.onClick(MainActivity.java:49)
07-06 00:50:04.516: E/AndroidRuntime(779): at android.view.View.performClick(View.java:4204)
07-06 00:50:04.516: E/AndroidRuntime(779): at android.view.View$PerformClick.run(View.java:17355)
07-06 00:50:04.516: E/AndroidRuntime(779): at android.os.Handler.handleCallback(Handler.java:725)
07-06 00:50:04.516: E/AndroidRuntime(779): at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 00:50:04.516: E/AndroidRuntime(779): at android.os.Looper.loop(Looper.java:137)
07-06 00:50:04.516: E/AndroidRuntime(779): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-06 00:50:04.516: E/AndroidRuntime(779): at java.lang.reflect.Method.invokeNative(Native Method)
07-06 00:50:04.516: E/AndroidRuntime(779): at java.lang.reflect.Method.invoke(Method.java:511)
07-06 00:50:04.516: E/AndroidRuntime(779): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-06 00:50:04.516: E/AndroidRuntime(779): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-06 00:50:04.516: E/AndroidRuntime(779): at dalvik.system.NativeStart.main(Native Method)
启动画面工作正常,但是当我点击按钮时,它总是说不幸停止了。怎么了?
答案 0 :(得分:1)
试试这种方式,
<Button
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To Do List"
android:onClick="Button_Click"
android:clickable="true" />
现在在Java类
中 public void Button_Click(View i)
{
Intent intent = new Intent(getApplicationContext(),YOUR_CLASS_NAME.class);
startActivity(intent);
}
答案 1 :(得分:0)
清单文件中有两个意图。尝试删除goToToDolist活动中的意图。
答案 2 :(得分:0)
在 button1Click 方法中,尝试更改以下内容:
startActivity(new Intent("com.example.splashscreen.ToDoList"));
为:
startActivity(new Intent(this, com.example.splashscreen.ToDoList.class));
发生这种情况的原因是因为根据Intent文档,您尝试创建意图的方式是错误的。您提供了一个包位置,但它需要一个操作。
答案 3 :(得分:0)
试试这段代码:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity{
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
button1 = (Button)findViewById(R.id.Button01);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, ToDoList.class);
startActivity(i);
}
});
}
}
我希望它有所帮助。