Android Activity does not open

0

I'm making a retrofit connection app, but I'm not understanding why my activity is not opening.

My code:

public class CotacaoAlteraActivity  extends AppCompatActivity {
private ListView listView;
ProgressBar pbar;
EditText custoalterar, embalagemalterar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cotacao_altera);

    EnviarAlteracao = (Button) findViewById(R.id.enviaralteracao);
    EnviarAlteracao.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        }
    });

    String cnpjfornecedor = getSharedPreferences(PREFS_USER, Context.MODE_PRIVATE).getString("PrefCnpj", "");
    String codigoproduto = getSharedPreferences(PREFS_COD, Context.MODE_PRIVATE).getString("PrefCod", "");

    loadCotacaoAlterar(cnpjfornecedor, codigoproduto);

    pbar = (ProgressBar) findViewById(R.id.progressBar4);
    listView = (ListView) findViewById(R.id.listView4);

}

public void loadEnviarCotacaoNova(Cotacao cotacao){ //Função POST para enviar os produtos para próxima página pra alterar.

    Retrofit.Builder builder = new Retrofit.Builder()
            .baseUrl("http://192.168.25.212:8080/CotacaoWebService/webresources/cotacao/")
            .addConverterFactory(GsonConverterFactory.create());

    Retrofit retrofit = builder.build();

    CotacaoEnviarAlteracaoClient client = retrofit.create(CotacaoEnviarAlteracaoClient.class);
    Call<Cotacao> call = client.reposForUser(cotacao);

    call.enqueue(new Callback<Cotacao>() {
        @Override
        public void onResponse(Call<Cotacao> call, Response<Cotacao> response) {
            Cotacao shop = response.body();
            Toast.makeText(getApplicationContext(), "Código: " + shop.getCodigoProduto(), Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onFailure(Call<Cotacao> call, Throwable t) {
            Toast.makeText(CotacaoAlteraActivity.this, "Produto inserido na lista", Toast.LENGTH_SHORT).show();
        }
    });
}

public void loadCotacaoAlterar(String buscar, String codigo) {
    Retrofit.Builder builder = new Retrofit.Builder()
            .baseUrl("http://192.168.25.212:8080/CotacaoWebService/webresources/cotacao/")
            .addConverterFactory(GsonConverterFactory.create());

    Retrofit retrofit = builder.build();

    CotacaoAlterarGETClient client = retrofit.create(CotacaoAlterarGETClient.class);
    Call<List<Cotacao>> call = client.reposForUser(buscar, codigo);

    call.enqueue(new Callback<List<Cotacao>>() {
        @Override
        public void onResponse(Call<List<Cotacao>> call, Response<List<Cotacao>> response) {
            pbar.setVisibility(View.GONE);
            List<Cotacao> repos = response.body();
            listView.setAdapter(new CotacaoAlterarAdapter(CotacaoAlteraActivity.this, repos));
            if (listView.getCount() == 0) {
                Toast.makeText(getApplicationContext(), "Nenhum produto localizado.", Toast.LENGTH_SHORT).show();
            }
        }
        @Override
        public void onFailure(Call<List<Cotacao>> call, Throwable t) {
            pbar.setVisibility(View.INVISIBLE);
            Toast.makeText(getApplicationContext(), "         Erro ao estabelecer conexão" + "\n"
                    + "            Verifique o host inserido" + "\n"
                    + "Por favor tente novamente mais tarde!", Toast.LENGTH_SHORT).show();
        }
    });
}
}

Error:

10-25 15:49:09.696 13243-13243/br.com.cotacaovolpix.cotacaovolpix E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                Process: br.com.cotacaovolpix.cotacaovolpix, PID: 13243
                                                                                java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.cotacaovolpix.cotacaovolpix/br.com.cotacaovolpix.cotacaovolpix.CotacaoAlteraActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2678)
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743)
                                                                                    at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                    at android.os.Looper.loop(Looper.java:154)
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:6165)
                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Erro está aqui>>>>
                                                                                 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
                                                                                    at br.com.cotacaovolpix.cotacaovolpix.CotacaoAlteraActivity.onCreate(CotacaoAlteraActivity.java:39)
                                                                                    at android.app.Activity.performCreate(Activity.java:6687)
                                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2631)
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743) 
                                                                                    at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490) 
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                    at android.os.Looper.loop(Looper.java:154) 
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:6165) 
                                                                                    at java.lang.reflect.Method.invoke(Native Method) 
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) 
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778) 
    
asked by anonymous 24.10.2017 / 19:20

1 answer

0

One reason might be that you are referencing an Id of a TextView or another element, incorrectly in your Activity. If this is not the case, try changing the element IDs and try to DEBUG your code with the help of breakPoints, and send us the line where the error occurred.

Make sure your activity is declared in the Manifest of your application, as in the example below:

<application...

<activity android:name="fiscale.vc.android.dialog_novidade" android:label="Novidade no Fiscale.vc">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
        </intent-filter>
    </activity> 

    
07.11.2017 / 17:47