gpt4 book ai didi

android - 应用程序不适用于 Android 4.0.3,但适用于 Android 2.3.4

转载 作者:行者123 更新时间:2023-11-29 14:53:59 25 4
gpt4 key购买 nike

我有一个应用程序可以在 Android 2.3.4(模拟器/手机)上完美运行。但我试图将它安装在 Android 4.0.3(模拟器/手机)上,当我运行它时它不工作。它向我展示了这条消息

"Unfortunately AppName has stopped"

当应用程序执行这些类时出现错误:

public class EmpleadosAct extends Activity {

private ArrayList<String> datos;
private ListView list;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActualizarVehiculos();

}

public void ActualizarVehiculos() {

try {
NotesCenter messageCenter = new NotesCenterImpl();

List<Vehiculo> vehiculo = messageCenter.getVehiculo();

for (Vehiculo v : vehiculo) {
AndroidOpenDbHelper androidOpenDbHelperObj = new AndroidOpenDbHelper(
this);

SQLiteDatabase sqliteDatabase = androidOpenDbHelperObj
.getWritableDatabase();

ContentValues contentValues = new ContentValues();
contentValues.put(AndroidOpenDbHelper.matricula, v.matricula);

long affectedColumnId = sqliteDatabase.insert("Vehiculos",
null, contentValues);
sqliteDatabase.close();
}
} catch (Exception ex) {
Log.v("blah", ex.getMessage());

}

}
}

第二类:

public class SeleccionarEmpleado extends Activity implements OnClickListener,
OnItemClickListener {

private ListView listaEmpleados;
private EditText ECont;
String text;
Bundle dataBundle;
public EmpleadosAct actemple;
protected AppApplication app;

private ListAdapter uGraduateListAdapter;

private ArrayList<UndergraduateDetailsPojo> pojoArrayList;
private String contraseña;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.seleccionarempleado);

***Intent actServicios = new Intent(this, EmpleadosAct.class);
startActivity(actServicios);***

listaEmpleados = (ListView) findViewById(R.id.ListaEmpleados);
listaEmpleados.setOnItemClickListener(this);

pojoArrayList = new ArrayList<UndergraduateDetailsPojo>();

uGraduateListAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, populateList());

listaEmpleados.setAdapter(uGraduateListAdapter);

}

public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case R.id.actualizar:
//Intent actualizarEmpleados = new Intent(this,EmpleadosAct.class);
//startActivity(actualizarEmpleados);


//return true;

case R.id.opciones:
Toast.makeText(SeleccionarEmpleado.this, "Save is Selected",
Toast.LENGTH_SHORT).show();
return true;

default:
return super.onOptionsItemSelected(item);
}
}

public void onClick(View v) {
Intent addNewUndergraduateIntent = new Intent(this,
InsertarPedido.class);
startActivity(addNewUndergraduateIntent);
}

public List<String> populateList() {

List<String> uGraduateNamesList = new ArrayList<String>();

AndroidOpenDbHelper openHelperClass = new AndroidOpenDbHelper(this);

SQLiteDatabase sqliteDatabase = openHelperClass.getReadableDatabase();

Cursor cursor = sqliteDatabase.query("Empleados", null, null, null,
null, null, null);

startManagingCursor(cursor);

while (cursor.moveToNext()) {

String idempleado = cursor.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.idempleado));
String nombre = cursor.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.nombre));
String primerapellido = cursor.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.primerapellido));
String segundoapellido = cursor.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.segundoapellido));
String contra = cursor.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.contra));

UndergraduateDetailsPojo ugPojoClass = new UndergraduateDetailsPojo();
ugPojoClass.setIdEmpleado(idempleado);
ugPojoClass.setNombreEmpleado(nombre);
ugPojoClass.setPrimerApellido(primerapellido);
ugPojoClass.setSegundoApellido(segundoapellido);
ugPojoClass.setContra(contra);

pojoArrayList.add(ugPojoClass);

uGraduateNamesList.add(nombre + " " + primerapellido + " "
+ segundoapellido);
}

sqliteDatabase.close();

return uGraduateNamesList;
}

@Override
protected void onResume() {
super.onResume();
uGraduateListAdapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, populateList());
listaEmpleados.setAdapter(uGraduateListAdapter);
}

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

UndergraduateDetailsPojo clickedObject = pojoArrayList.get(arg2);

String Empleado = clickedObject.getNombreEmpleado() + " "
+ clickedObject.getPrimerApellido() + " "
+ clickedObject.getSegundoApellido();

Empleado empleadoseleccionado = new Empleado();
empleadoseleccionado.id = clickedObject.getIdEmpleado();
empleadoseleccionado.nombre = Empleado;
app = (AppApplication)getApplicationContext();
app.setempleadoActual(empleadoseleccionado);
app.setempleadoId(empleadoseleccionado);

}
}

一开始是在执行第二个类,在第二个类中有一个打开第一个类的Intent。第一类从某个远程服务器向 android SQLite 数据库添加数据。然后第二个类显示来自 android SQLite 数据库的结果。

这是日志:

06-04 21:08:13.034: W/dalvikvm(517): threadid=1: thread exiting with uncaught exception    (group=0x409c01f8)
06-04 21:08:13.054: E/AndroidRuntime(517): FATAL EXCEPTION: main
06-04 21:08:13.054: E/AndroidRuntime(517): java.lang.RuntimeException: Unable to start activity ComponentInfo{dokesim.net/myapp.net.EmpleadosAct}: java.lang.NullPointerException: println needs a message
06-04 21:08:13.054: E/AndroidRuntime(517): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-04 21:08:13.054: E/AndroidRuntime(517): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-04 21:08:13.054: E/AndroidRuntime(517): at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-04 21:08:13.054: E/AndroidRuntime(517): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-04 21:08:13.054: E/AndroidRuntime(517): at android.os.Handler.dispatchMessage(Handler.java:99)
06-04 21:08:13.054: E/AndroidRuntime(517): at android.os.Looper.loop(Looper.java:137)
06-04 21:08:13.054: E/AndroidRuntime(517): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-04 21:08:13.054: E/AndroidRuntime(517): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 21:08:13.054: E/AndroidRuntime(517): at java.lang.reflect.Method.invoke(Method.java:511)
06-04 21:08:13.054: E/AndroidRuntime(517): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-04 21:08:13.054: E/AndroidRuntime(517): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-04 21:08:13.054: E/AndroidRuntime(517): at dalvik.system.NativeStart.main(Native Method)
06-04 21:08:13.054: E/AndroidRuntime(517): Caused by: java.lang.NullPointerException: println needs a message
06-04 21:08:13.054: E/AndroidRuntime(517): at android.util.Log.println_native(Native Method)
06-04 21:08:13.054: E/AndroidRuntime(517): at android.util.Log.v(Log.java:117)
06-04 21:08:13.054: E/AndroidRuntime(517): at myapp.net.EmpleadosAct.ActualizarVehiculos(EmpleadosAct.java:133)
06-04 21:08:13.054: E/AndroidRuntime(517): at myapp.net.EmpleadosAct.onCreate(EmpleadosAct.java:24)
06-04 21:08:13.054: E/AndroidRuntime(517): at android.app.Activity.performCreate(Activity.java:4465)
06-04 21:08:13.054: E/AndroidRuntime(517): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-04 21:08:13.054: E/AndroidRuntime(517): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-04 21:08:13.054: E/AndroidRuntime(517): ... 11 more

第二个日志:

06-04 21:40:03.225: V/blah(720): Error happened: 
06-04 21:40:03.225: V/blah(720): android.os.NetworkOnMainThreadException
06-04 21:40:03.225: V/blah(720): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
06-04 21:40:03.225: V/blah(720): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
06-04 21:40:03.225: V/blah(720): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
06-04 21:40:03.225: V/blah(720): at libcore.io.IoBridge.connect(IoBridge.java:112)
06-04 21:40:03.225: V/blah(720): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
06-04 21:40:03.225: V/blah(720): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
06-04 21:40:03.225: V/blah(720): at java.net.Socket.connect(Socket.java:842)
06-04 21:40:03.225: V/blah(720): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
06-04 21:40:03.225: V/blah(720): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
06-04 21:40:03.225: V/blah(720): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
06-04 21:40:03.225: V/blah(720): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119 )
06-04 21:40:03.225: V/blah(720): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
06-04 21:40:03.225: V/blah(720): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
06-04 21:40:03.225: V/blah(720): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
06-04 21:40:03.225: V/blah(720): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
06-04 21:40:03.225: V/blah(720): at myapp.net.HttpNote.doGet(HttpNote.java:32)
06-04 21:40:03.225: V/blah(720): at myapp.net.NotesCenterImpl.getVehiculo(NotesCenterImpl.java:23)
06-04 21:40:03.225: V/blah(720): at myapp.net.EmpleadosAct.ActualizarVehiculo(EmpleadosAct.java:91)
06-04 21:40:03.225: V/blah(720): at myapp.net.EmpleadosAct.onCreate(EmpleadosAct.java:24)
06-04 21:40:03.225: V/blah(720): at android.app.Activity.performCreate(Activity.java:4465)
06-04 21:40:03.225: V/blah(720): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-04 21:40:03.225: V/blah(720): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-04 21:40:03.225: V/blah(720): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-04 21:40:03.225: V/blah(720): at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-04 21:40:03.225: V/blah(720): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-04 21:40:03.225: V/blah(720): at android.os.Handler.dispatchMessage(Handler.java:99)
06-04 21:40:03.225: V/blah(720): at android.os.Looper.loop(Looper.java:137)
06-04 21:40:03.225: V/blah(720): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-04 21:40:03.225: V/blah(720): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 21:40:03.225: V/blah(720): at java.lang.reflect.Method.invoke(Method.java:511)
06-04 21:40:03.225: V/blah(720): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-04 21:40:03.225: V/blah(720): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-04 21:40:03.225: V/blah(720): at dalvik.system.NativeStart.main(Native Method)

那么是什么原因导致 android 在 2.3.4 中一切正常,而在 4.0.3 中却不行?我的代码有问题不支持 4.0.3 版本?

感谢您的任何回答或建议。

最佳答案

Log.v("blah", ex.getMessage());

问题是 ex.getMessage() 正在返回 null。您可以检查 null,但更好的方法是将异常作为第三个参数显式传递给日志方法:

Log.v("blah", "Error happened: ", ex);

关于android - 应用程序不适用于 Android 4.0.3,但适用于 Android 2.3.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10888584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com