作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
我终于成功访问了postgres,但是方法不符合要求。通过第一种方法我可以连接,但通过第二种方法我收到以下错误。
这是我的代码。
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button login = (Button) findViewById(R.id.Connect);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//new JSONTask().execute("file:///C:/Users/intel/Desktop/details.json");
System.out.println("Connection Start");
new PostgreSqlJDBC().execute();
}
});
}
public class PostgreSqlJDBC extends AsyncTask<Void, Void, Void> {
@Override
public Void doInBackground(Void... params) {
Connection conexion = null;
System.out.println("Connection Intitializing");
try {
Class.forName("org.postgresql.Driver");
String url="jdbc:postgresql://192.168.0.5:5432/Taxi";
conexion = DriverManager.getConnection(url, "admin", "123");
System.out.println("Connection Successfull");
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
System.err.println("Error: Cant connect!");
System.err.println("----- PostgreSQL query ends correctly!-----");
return null;
}
return null;
}
}
}
但我想通过这种方式访问它。 CONNECT 方法是对 xml 中按钮的引用。
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void Connect(View v) {
Connection conexion = null;
System.out.println("Connection Intitializing");
try {
Class.forName("org.postgresql.Driver");
String url="jdbc:postgresql://192.168.0.5:5432/Taxi";
conexion = DriverManager.getConnection(url, "admin", "123");
System.out.println("Connection Successfull");
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
System.err.println("Error: Cant connect!");
System.err.println("----- PostgreSQL query ends correctly!-----");
}
}
}
控制台中的日志输出。
09-13 00:08:10.990 6948-6948/? I/System.out﹕ Connection Intitializing
09-13 00:08:10.993 1233-1294/? W/AudioTrack﹕ AUDIO_OUTPUT_FLAG_FAST denied by client
09-13 00:08:11.079 6948-6948/? W/System.err﹕ org.postgresql.util.PSQLException: Something unusual has occurred to cause the driver to fail. Please report this exception.
09-13 00:08:11.079 6948-6948/? W/System.err﹕ at org.postgresql.Driver.connect(Driver.java:295)
09-13 00:08:11.079 6948-6948/? W/System.err﹕ at java.sql.DriverManager.getConnection(DriverManager.java:179)
09-13 00:08:11.079 6948-6948/? W/System.err﹕ at java.sql.DriverManager.getConnection(DriverManager.java:213)
09-13 00:08:11.079 6948-6948/? W/System.err﹕ at com.echotaxicab.MainActivity.Connect(MainActivity.java:42)
09-13 00:08:11.079 6948-6948/? W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
09-13 00:08:11.079 6948-6948/? W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
09-13 00:08:11.079 6948-6948/? W/System.err﹕ at android.view.View$1.onClick(View.java:4015)
09-13 00:08:11.079 6948-6948/? W/System.err﹕ at android.view.View.performClick(View.java:4780)
09-13 00:08:11.079 6948-6948/? W/System.err﹕ at android.view.View$PerformClick.run(View.java:19866)
09-13 00:08:11.079 6948-6948/? W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
09-13 00:08:11.079 6948-6948/? W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
09-13 00:08:11.080 6948-6948/? W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
09-13 00:08:11.080 6948-6948/? W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5257)
09-13 00:08:11.080 6948-6948/? W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
09-13 00:08:11.080 6948-6948/? W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
09-13 00:08:11.080 6948-6948/? W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
09-13 00:08:11.080 6948-6948/? W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
09-13 00:08:11.080 6948-6948/? W/System.err﹕ Caused by: android.os.NetworkOnMainThreadException
09-13 00:08:11.080 6948-6948/? W/System.err﹕ at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
09-13 00:08:11.080 6948-6948/? W/System.err﹕ at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:110)
09-13 00:08:11.080 6948-6948/? W/System.err﹕ at libcore.io.IoBridge.connectErrno(IoBridge.java:154)
09-13 00:08:11.080 6948-6948/? W/System.err﹕ at libcore.io.IoBridge.connect(IoBridge.java:122)
09-13 00:08:11.080 6948-6948/? W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
09-13 00:08:11.081 6948-6948/? W/System.err﹕ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
09-13 00:08:11.081 6948-6948/? W/System.err﹕ at java.net.Socket.connect(Socket.java:882)
09-13 00:08:11.081 6948-6948/? W/System.err﹕ at org.postgresql.core.PGStream.<init>(PGStream.java:64)
09-13 00:08:11.081 6948-6948/? W/System.err﹕ at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:147)
09-13 00:08:11.081 6948-6948/? W/System.err﹕ at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:54)
09-13 00:08:11.081 6948-6948/? W/System.err﹕ at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:218)
09-13 00:08:11.081 6948-6948/? W/System.err﹕ at org.postgresql.Driver.makeConnection(Driver.java:407)
09-13 00:08:11.081 6948-6948/? W/System.err﹕ at org.postgresql.Driver.connect(Driver.java:275)
09-13 00:08:11.081 6948-6948/? W/System.err﹕ ... 16 more
09-13 00:08:11.081 6948-6948/? W/System.err﹕ Something unusual has occurred to cause the driver to fail. Please report this exception.
09-13 00:08:11.081 6948-6948/? W/System.err﹕ Error: Cant connect!
09-13 00:08:11.081 6948-6948/? W/System.err﹕ ----- PostgreSQL query ends correctly!-----
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!