我已看網路教學也跟者匯入了但還是會出現錯誤 拜託各位網友了
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.wells.ndr_text, PID: 7246
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/client/HttpClient;
at com.example.wells.ndr_text.DBphp.DBstring(DBphp.java:47)
at com.example.wells.ndr_text.ndr_text1.select(ndr_text1.java:99)
at com.example.wells.ndr_text.ndr_text1$3.run(ndr_text1.java:92)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.client.HttpClient" on path: DexPathList[[zip file "/data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/base.apk", zip file "/data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/split_lib_resources_apk.apk", zip file "/data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.example.wells.ndr_text.DBphp.DBstring(DBphp.java:47)
at com.example.wells.ndr_text.ndr_text1.select(ndr_text1.java:99)
at com.example.wells.ndr_text.ndr_text1$3.run(ndr_text1.java:92)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
at android.app.LoadedApk.getResources(LoadedApk.java:1032)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5749)
E/AndroidRuntime: at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
... 5 more
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.wells.ndr_text-QypzX3pz43lhX71oztQTVg==/split_lib_slice_8_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
at android.app.LoadedApk.getResources(LoadedApk.java:1032)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5749)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
package com.example.wells.ndr_text;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class DBphp {
private static HttpClient hC;
private static HttpPost hP;
public static String DBstring(String i,String Wcook,String url){
String result="錯誤";
try{
hC=new DefaultHttpClient();
hP=new HttpPost(url+"/index.php");
hP.addHeader("Cookie",Wcook+";expires=thu,31-Dec-37 23:55:22 GHT; path=/");
ArrayList<NameValuePair> params=new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("S1",i));
hP.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
HttpResponse hR=hC.execute(hP);
HttpEntity hE=hR.getEntity();
InputStream inputStream=hE.getContent();
BufferedReader bufReader=new BufferedReader(new InputStreamReader(inputStream,HTTP.UTF_8),8);
StringBuilder builder =new StringBuilder();
String line=null;
while((line = bufReader.readLine())!=null){
builder.append(line+"\n");
}
inputStream.close();
result=builder.toString();
}catch (Exception e){
result=e.toString();
}finally {
hC.getConnectionManager().shutdown();
}
return result;
}
}
package com.example.wells.ndr_text;
import android.content.Context;
import android.os.Handler;
import android.os.StrictMode;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import org.apache.http.cookie.params.CookieSpecPNames;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ndr_text1 extends AppCompatActivity {
Context context =this;
EditText et1,et2,et3,et4;
WebView webview;
String url="http://ksuwork.byethost16.com/";
CookieManager cookeManager;
String cookieStr,id_text;
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedClosableObjects().detectLeakedSqlLiteObjects().penaltyDeath().penaltyLog().build());
Wcookie(context);
Handler myHandler=new Handler();
myHandler.postDelayed(runTimerStop,15000);
if(cookieStr!=null){
myHandler.removeCallbacks(runTimerStop);
}
listView=findViewById(R.id.LV1);
et1=findViewById(R.id.et1);
et2=findViewById(R.id.et2);
et3=findViewById(R.id.et3);
et4=findViewById(R.id.et4);
//新增資廖
Button b1=findViewById(R.id.save);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] et0=new String[]{et1.getText().toString(),et2.getText().toString(),et3.getText().toString(),et4.getText().toString()};
Inphp.Interting(et0,cookieStr,url);
select(null);
}
});
}
private void Wcookie(Context context) {
CookieSyncManager.createInstance(context);
cookeManager=CookieManager.getInstance();
webview=new WebView(context);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient(){
@Override
public void onPageCommitVisible(WebView view, String url) {
super.onPageCommitVisible(view, url);
cookeManager.setAcceptCookie(true);
cookieStr=cookeManager.getCookie(url);
}
});
webview.loadUrl(url);
webview.clearHistory();
webview.clearCache(true);
cookeManager.removeAllCookie();
cookeManager.removeSessionCookie();
}
private Runnable runTimerStop = new Runnable() {
@Override
public void run() {
select(null);
}
};
//顯示
public void select(String id){
try{
String r=DBphp.DBstring(id,cookieStr,url);
JSONArray jsonArray = new JSONArray(r);
List<Map<String,Object>> items = new ArrayList<Map<String,Object>>();
for(int i=0;i<jsonArray.length();i++){
JSONObject jsonData=jsonArray.getJSONObject(i);
Map<String,Object> item=new HashMap<String,Object>();
item.put("id",jsonData.getString("id"));
item.put("email",jsonData.getString("email"));
item.put("password",jsonData.getString("password"));
item.put("name",jsonData.getString("name"));
item.put("hint",jsonData.getString("hint"));
items.add(item);//新增到item
}
SimpleAdapter SA=new SimpleAdapter(context,items,R.layout.list_text,new String[]{"id","email","password","name","hint"},new int[]{R.id.text0,R.id.text1,R.id.text2,R.id.text3,R.id.text4});
listView.setAdapter(SA);
} catch (Exception e){
Log.e("log_tag=",e.toString());
}
}
}
package com.example.wells.ndr_text;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import java.util.ArrayList;
public class Inphp {
private static HttpClient hC;
private static HttpPost hP;
public static void Interting(String[] i,String Wcook,String url){
String result = "錯誤";
try {
hC = new DefaultHttpClient();
hP = new HttpPost(url + "Intert_text1.php");
System.out.println("是否取得cookie=" + Wcook);
hP.addHeader("Cookie", Wcook + ";expires=Thu, 31-Dec-37 23:55:55 GMT; path=/");
ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("S1", i[0]));
params.add(new BasicNameValuePair("S2", i[1]));
params.add(new BasicNameValuePair("S3", i[2]));
params.add(new BasicNameValuePair("S4", i[3]));
hP.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
HttpResponse hR = hC.execute(hP);
hR.getEntity();
} catch (Exception e) {
System.out.print(e.toString());
} finally {
hC.getConnectionManager().shutdown();
}
}
}