0

どの apk が Gingerbread では完全に機能するかを調べようとしていますが、ICS や Jelly bean では機能しません。データベースから情報を取得するときに次のエラーが発生します。

ジンジャーブレッドではすべて正常に動作します。このアクティビティに入ると、データベースに保存したすべての情報が表示されますが、ICS または Jeally Bean では、アプリケーションが閉じてメイン アクティビティに戻ります。誰か私を助けてくれませんか!?

09-29 21:18:21.802: W/dalvikvm(26432): threadid=1: thread exiting with uncaught exception (group=0x40aa8210)
09-29 21:18:21.810: E/AndroidRuntime(26432): FATAL EXCEPTION: main
09-29 21:18:21.810: E/AndroidRuntime(26432): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mota.DroidTeca/com.prueba.bibliotecaappprueba.DetallesActivity}: java.lang.NullPointerException
09-29 21:18:21.810: E/AndroidRuntime(26432):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1973)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2083)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at android.app.ActivityThread.access$600(ActivityThread.java:134)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1233)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at android.os.Looper.loop(Looper.java:137)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at android.app.ActivityThread.main(ActivityThread.java:4697)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at java.lang.reflect.Method.invokeNative(Native Method)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at java.lang.reflect.Method.invoke(Method.java:511)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at dalvik.system.NativeStart.main(Native Method)
09-29 21:18:21.810: E/AndroidRuntime(26432): Caused by: java.lang.NullPointerException
09-29 21:18:21.810: E/AndroidRuntime(26432):    at com.prueba.bibliotecaappprueba.FileCache.<init>(FileCache.java:19)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at com.prueba.bibliotecaappprueba.ImageLoader.<init>(ImageLoader.java:34)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at com.prueba.bibliotecaappprueba.DetallesActivity.<init>(DetallesActivity.java:50)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at java.lang.Class.newInstanceImpl(Native Method)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at java.lang.Class.newInstance(Class.java:1319)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
09-29 21:18:21.810: E/AndroidRuntime(26432):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1964)
09-29 21:18:21.810: E/AndroidRuntime(26432):    ... 11 more

これは私のコードです:

public class DetallesActivity extends Activity {
//Variables
    public static final String PREFS_NAME1 = "MyPrefsFile1";
    public ImageLoader imageLoader;
    {

        imageLoader = new ImageLoader(null);
    }

    TextView txtNama;
    TextView txtLinkImage;
    TextView txtAlamat;
    TextView txtTelepon;
    TextView txtFax;
    TextView txtEmail;
    TextView txtWebsite;
    String descarg;
    String id_rs;
    String nomb;
    private ProgressDialog pDialog;

    JSONParser jsonParser = new JSONParser();

    private static final String url_detail_rs = "http://example_link/detalles.php";
    public int i = 0;
    private static final String TAG_SUCCESS = "success";
    private static final String TAG_DAFTAR_RS = "daftar_rs";
    private static final String TAG_ID_RS = "id_rs";
    public static final String TAG_NOMBRE_RS = "nombre_rs";
    public static final String TAG_LINK_IMAGE_RS = "link_image_rs";
    public static final String TAG_AUTOR_RS = "autor_rs";
    public static final String TAG_CATEG_RS = "categ_rs";
    public static final String TAG_LINK_DESCARGA_RS = "link_descarga_rs";;
    private static final String TAG_SIPNOSIS_RS = "sipnosis";
    public static final int DIALOG_DOWNLOAD_PROGRESS = 0;
    private ProgressDialog mProgressDialog;
  //Variables fin
    @Override
    public void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail_rs);


        Intent i = getIntent();

        id_rs = i.getStringExtra(TAG_ID_RS);;

        new GetDetailrs().execute();
         SharedPreferences settings = getSharedPreferences(PREFS_NAME1, 0);
            boolean dialogShown = settings.getBoolean("dialogShown", false);


            if (!dialogShown) {
              // AlertDialog code here
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage("El Botón de Descarga se encuentra al final de la descripción" + "\n" +
                        "- Haz Scroll hasta llegar al final."+ "\n" +
                        "- Pulsa el botón 'Descargar' y espera unos segundos." + "\n" +
                        "Podrás disfrutar de tu Libro descargado desde tu Lector de preferencia!. ")
                        .setTitle("Atencion!")
                        .setCancelable(false)
                        .setNeutralButton("Aceptar",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                });
                AlertDialog alert = builder.create();
                alert.show();
                ((TextView)alert.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
              SharedPreferences.Editor editor = settings.edit();
              editor.putBoolean("dialogShown", true);
              editor.commit();    


            }
    }



//Termina Bundle
    private void startDownload() {
        String url = descarg;
        new DownloadFileAsync().execute(url);
    }
//Termina inicio de descarga
    //Termina el inicio de descarga
        @Override
        protected Dialog onCreateDialog(int id) {
            switch (id) {
            case DIALOG_DOWNLOAD_PROGRESS:
                mProgressDialog = new ProgressDialog(this);
                mProgressDialog.setMessage("Descargando Libro..");
                mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                mProgressDialog.setCancelable(false);
                mProgressDialog.show();
                return mProgressDialog;
            default:
                return null;
            }
        }
    //Termina el DIalog descargando...
        class DownloadFileAsync extends AsyncTask<String, String, String> {

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                showDialog(DIALOG_DOWNLOAD_PROGRESS);
            }
            //termina einicio dialgo
            @Override
            protected String doInBackground(String... aurl) {
                int count;

            try {

            URL url = new URL(aurl[0]);
            HttpURLConnection c = (HttpURLConnection) url.openConnection();
            c.setRequestMethod("GET");
            c.setDoOutput(true);
            c.connect();

            int lenghtOfFile = c.getContentLength();
            Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);

            InputStream input = new BufferedInputStream(url.openStream());
            OutputStream output = new FileOutputStream("/sdcard/Mi Biblioteca/"+nomb+ ".epub");

            byte data[] = new byte[1024];

            long total = 0;

                while ((count = input.read(data)) != -1) {
                    total += count;
                    publishProgress(""+(int)((total*100)/lenghtOfFile));
                    output.write(data, 0, count);
                }

                output.flush();
                output.close();
                input.close();
            } catch (Exception e) {}
            return null;

            }
            //Termina almacenamiento

    protected void onProgressUpdate(String... progress) {
         Log.d("ANDRO_ASYNC",progress[0]);
         mProgressDialog.setProgress(Integer.parseInt(progress[0]));

    }
    //Progreso llega a 0

    @Override
    protected void onPostExecute(String unused) {
        dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
          Intent intent1 = getIntent();
          finish();
          startActivity(intent1);

    }
    //Progreso se cierra
        }
    class GetDetailrs extends AsyncTask<String, String, String> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(DetallesActivity.this);
            pDialog.setMessage("Cargando esperar ... !");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }

        protected String doInBackground(String... params) {
            Conexion();
            if (i == 0) {
            runOnUiThread(new Runnable() {
                public void run() {

                    int success;
                    try {

                        List<NameValuePair> params = new ArrayList<NameValuePair>();
                        params.add(new BasicNameValuePair("id_rs",
                                id_rs));

                        JSONObject json = jsonParser.makeHttpRequest(
                                url_detail_rs, "GET", params);

                        Log.d("rs Detail", json.toString());

                        success = json.getInt(TAG_SUCCESS);
                        if (success == 1) {

                            JSONArray productObj = json
                                    .getJSONArray(TAG_DAFTAR_RS);

                            JSONObject daftar_rs = productObj.getJSONObject(0);

                            txtNama = (TextView) findViewById(R.id.nama_rs);
                            txtLinkImage = (TextView) findViewById(R.id.link_image_rs);
                            txtAlamat = (TextView) findViewById(R.id.alamat_rs);
                            txtTelepon = (TextView) findViewById(R.id.telepon_rs);
                            txtFax = (TextView) findViewById(R.id.fax_rs);
                            txtEmail = (TextView) findViewById(R.id.email_rs);


                            ImageView thumb_image = (ImageView) findViewById(R.id.list_image);

                            txtNama.setText(daftar_rs.getString(TAG_NOMBRE_RS));

                            txtLinkImage.setText(daftar_rs
                                    .getString(TAG_LINK_IMAGE_RS));
                            txtAlamat.setText(daftar_rs
                                    .getString(TAG_AUTOR_RS));
                            txtTelepon.setText(daftar_rs
                                    .getString(TAG_CATEG_RS));
                            txtFax.setText(daftar_rs.getString(TAG_SIPNOSIS_RS));
                            txtEmail
                                    .setText(daftar_rs.getString(TAG_LINK_DESCARGA_RS));

                            descarg = new String(daftar_rs.getString(TAG_LINK_DESCARGA_RS));
                            nomb = new String(daftar_rs.getString(TAG_NOMBRE_RS));

                            imageLoader.DisplayImage(daftar_rs
                                    .getString(TAG_LINK_IMAGE_RS),
                                    thumb_image);

                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                }
            });
            }
            else{ finish();
            }
            return null;
        }

        protected void onPostExecute(String file_url) {

            pDialog.dismiss();
//comiena prueba

            File extStore = Environment.getExternalStorageDirectory();
            File myFile = new File(extStore.getAbsolutePath() + "/Mi Biblioteca/"+nomb+".epub");
            if(myFile.exists()){

                Button leer = (Button) findViewById(R.id.Btnleer);
                leer.setVisibility(View.VISIBLE);
                Button dscr = (Button) findViewById(R.id.BtnDesc);
                dscr.setVisibility(View.INVISIBLE);
            }else{


                Button leer = (Button) findViewById(R.id.Btnleer);
                leer.setVisibility(View.INVISIBLE);
                Button dscr = (Button) findViewById(R.id.BtnDesc);
                dscr.setVisibility(View.VISIBLE);


            }
            //Termina el If e inicia descarga
            Button dscr = (Button) findViewById(R.id.BtnDesc);
            dscr.setOnClickListener(new OnClickListener(){
                 public void onClick(View v) {
                     startDownload();}

            });

            //inicia abrir archivo
            Button leer = (Button) findViewById(R.id.Btnleer);
            leer.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v2) {
                    // TODO Auto-generated method stub
                    File file = new File("/sdcard/Mi Biblioteca/"+nomb+".epub");
                    Intent intentreadf = new Intent(Intent.ACTION_VIEW);
                    intentreadf.setDataAndType(Uri.fromFile(file),"application/epub+zip");
                    intentreadf.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

                    try {
                        startActivity(intentreadf);
                    } 
                    catch (ActivityNotFoundException e) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(DetallesActivity.this);
                        builder.setMessage("No hay instalada Aplicacion Para leer Epubs" +
                                "Desea descargar una sugerída por Droidteca?")
                        .setTitle("Advertencia")
                        .setCancelable(false)
                        .setNegativeButton("Cancelar",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        dialog.cancel();

                                    }
                        })
                        .setPositiveButton("Descargar",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        try {
                                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.zoreader")));
                                        } catch (android.content.ActivityNotFoundException anfe) {
                                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.zoreader")));
                                        }
                                   // metodo que se debe implementar
                                    }
                                });
                AlertDialog alert = builder.create();
                alert.show();
    } 
                }

                });
            //finaliza abrir archivo
        }
    }
    private void Conexion() {
        // TODO Auto-generated method stub
        try {
            if (InetAddress.getByName("www.google.com").isReachable(3000))
            {  Intent nohay= new Intent(DetallesActivity.this, noActivity.class);
            onStop();
            i = 1;
            startActivity(nohay);
            }
            else{}
        } catch (UnknownHostException e) {
             Intent nohay= new Intent(DetallesActivity.this, noActivity.class);
            onStop();   
            i = 1;
             startActivity(nohay);

            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
             Intent nohay= new Intent(DetallesActivity.this, noActivity.class);
             onStop();
             i = 1;
             startActivity(nohay);


            // TODO Auto-generated catch block
            e.printStackTrace();
        }}




}

編集//

新しい LogCat エラー:

09-30 16:40:36.524: E/AndroidRuntime(30689): FATAL EXCEPTION: main
09-30 16:40:36.524: E/AndroidRuntime(30689): android.os.NetworkOnMainThreadException
09-30 16:40:36.524: E/AndroidRuntime(30689):    at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1119)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at java.net.InetAddress.lookupHostByName(InetAddress.java:441)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:243)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at java.net.InetAddress.getAllByName(InetAddress.java:220)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at com.prueba.bibliotecaappprueba.JSONParser.makeHttpRequest(JSONParser.java:62)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at com.prueba.bibliotecaappprueba.DetallesActivity$GetDetailrs$1.run(DetallesActivity.java:232)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at android.os.Handler.handleCallback(Handler.java:605)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at android.os.Handler.dispatchMessage(Handler.java:92)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at android.os.Looper.loop(Looper.java:137)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at android.app.ActivityThread.main(ActivityThread.java:4697)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at java.lang.reflect.Method.invokeNative(Native Method)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at java.lang.reflect.Method.invoke(Method.java:511)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
09-30 16:40:36.524: E/AndroidRuntime(30689):    at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1

1

こうすれば

この行を宣言部分から削除します

imageLoader = new ImageLoader(null);

この行を次のonCreate()ようにメソッドに記述します

imageLoader = new ImageLoader(this);
于 2013-09-30T04:09:18.053 に答える